• RedPitbull

    (@redpitbull)


    How to add a text widget only in single.php.

    For exemple, I want to put an add there, but I want it only in the posts pages, that is single.php. Can any one give me some sugesions please ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • lizzyb

    (@lizzyb)

    There is a great plugin called widget logic. You can specify what widgets you want to show on which page, or which type of page eg single.

    This should work for you.

    Liz

    Michael

    (@alchymyth)

    for instance, try to work with http://wordpress.org/extend/plugins/widget-logic/

    Depends on the theme you are using. If that doesn’t support widget area for posts only then you will have to edit the sidebar that loads into the single.php.

    You can have it render conditionally depending on if it is a post. So, in your sidebar file that loads into single.php have something like:

    if( is_single() ) {
    
      // code here to show on posts sidebar
    
    }

    The code you enter inside the is_single condition could be raw html like:

    <div class="widget widget_text">
    	<h3 class="widget-title">[enter title]</h3>
    	<div class="textwidget">[enter widget text]</div>
    </div>

    or you can get fancy and use the proper function to generate a text widget, like so:

    $text = array(
    		'title' => 'Widget Title',
    		'text' => 'Widget text.',
    		'filter' => ''
    	);
    	$text_args = array(
    		'before_widget' => '<div class="widget widget_text">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>'
    	);
    
    	the_widget( 'WP_Widget_Text', $text, $text_args );

    The end result will be pretty much the same.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add a text widget ?’ is closed to new replies.