ThemeShaper Forums » Thematic

[closed]

How to make Singe Insert behave like Index Insert

(7 posts)
  • Started 4 years ago by joeangelo
  • Latest reply from daveread
  • This topic is resolved
  1. Does anyone know of a way to make single insert behave like index insert? What I want is to have single insert appear after x-numbers of paragraphs on a post.

    This above might not be possible so is there a way to add a new widgetized area which can be called manually whenever you type a post?

    Thanks.

    Posted 4 years ago #
  2. Hi,

    ever thought about using shortcodes to realize this one?! :)

    No? .. let's do some magic (I'm not doing the whole work, only part of it):

    function widget_insidepost() {
    	// This is pretty weird, but it works. We start the cache ..
    	ob_start();
    	// .. *yikes* .. can't remember if this is SVN revision only or not .. it displays the CSS markup before the widget area
    	echo thematic_before_widget_area('single-insert');
    	// .. I know .. I'm lazy. I duplicated the single insert widget area.
    	dynamic_sidebar('single-insert');
    	// .. see comment above .. it displays the CSS markup after the widget area
    	echo thematic_after_widget_area('single-insert');
    	// Put everything from the black cauldron into $widget_inside
    	$widget_inside = ob_get_contents();
    	// end that caching process
    	ob_end_clean();
    	// return the ingredients
        return $widget_inside;
    }
    // Let's do some magic and exchange [widget-inside] against the ingredients
    add_shortcode('widget-inside', 'widget_insidepost');

    Use [widget-inside] somewhere in your post to display the widgetized area.

    It works .. any better ideas??

    Chris

    Posted 4 years ago #
  3. anthony99
    Member

    Hello Chris

    Any chance you could help me with my problem? I have an unresolved thread a bit farther down the page.

    THANK YOU.

    Posted 4 years ago #
  4. that's wicked cool =)

    Looks like a set up for a really long widgetcontext/widget logic entry.

    Posted 4 years ago #
  5. Hey Chris,

    Thanks for the detailed instructions on how you wave that magic wand :)

    Never thought about using widget logic before, thanks for the suggestion.

    I'll report back once i've made this work in the site.

    Posted 4 years ago #
  6. tested and working.

    For those who want to add a new widget area and not just duplicate "single-insert widget", try this code:

    //ADD new widget for widget-inside
    function my_widgets_init() {
        register_sidebar(array(
           	'name' => 'Widget Inside',
           	'id' => 'Widget Inside',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => "\n",
    		'before_title' => "<h3 class=\"widgettitle\">",
    		'after_title' => "</h3>\n",
        ));
    
    }
    add_action( 'init', 'my_widgets_init' );
    //End Widget-insdie code
    
    //Widget inside post
    function widget_insidepost() {
    	// This is pretty weird, but it works. We start the cache ..
    	ob_start();
    	// .. *yikes* .. can't remember if this is SVN revision only or not .. it displays the CSS markup before the widget area
    	echo thematic_before_widget_area('widget-inside');
    	// .. I know .. I'm lazy. I duplicated the single insert widget area.
    	dynamic_sidebar('widget-inside');
    	// .. see comment above .. it displays the CSS markup after the widget area
    	echo thematic_after_widget_area('widget-inside');
    	// Put everything from the black cauldron into $widget_inside
    	$widget_inside = ob_get_contents();
    	// end that caching process
    	ob_end_clean();
    	// return the ingredients
        return $widget_inside;
    }
    // Let's do some magic and exchange [widget-inside] against the ingredients
    add_shortcode('widget-inside', 'widget_insidepost');

    The original code simply duplicates the "single-insert" inside the post. I added a code to create a new widgetized area and edited Chris' code to display the "widget-inside" widget instead of single-insert.

    And if you want to save some time in writing "[widget-inside]" for every new post, add this code in your functions.php file as well:

    function my_default_post_content()
    {
    $dpc = '[widget-inside]';
    return $dpc;
    }
    add_filter('default_content', 'my_default_post_content');

    Posted 4 years ago #
  7. Thanks for this, BUT - any ideas why I still need to insert shortcode on posts/pages, even though the new widget shows up with all the others in the admin panel? BUT it works as advertised on my other site which uses the same child theme? Here they are:
    http://www.berkshirelinks.com (needs shortcode);
    http://www.newberkshire.com.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.