How to add a widget top of the posts
-
Hello everyone
I creat a side bar with widget for my blog how i can define the sidebar that appear top of the my posts .
now the sidebar shows at the right column of my theme
thabks!
-
You need to add the widgetized sidebar code to the appropriate location in your template files.
For example, if you registered your sidebar as follows, in functions.php:
{{{
register_sidebar(array( // Above Posts widget area
‘name’=>’sidebar-posts-before’,
‘description’ => ‘Area to display Widgets above Posts’,
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<div class=”title widgettitle”>’,
‘after_title’ => ‘</div>’,
));
}}}
Then, you need to modify the appropriate template file so that before the Loop*, you call the following:
{{{
<?php if ( !dynamic_sidebar( ‘sidebar-posts-before’ ) ) {
// Put any default (i.e. no-Widget) output here
} ?>
}}}* Note: The start of the Loop looks something like this (perhaps in index.php, or loop.php, etc.):
{{{
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
}}}
If you want this widgetized area to appear before *all* Posts, then, it should go immediately before the line above, e.g.:
{{{
<?php if ( !dynamic_sidebar( ‘sidebar-posts-before’ ) ) {
// Put any default (i.e. no-Widget) output here
}
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
}}}Whoops; Trac formatting doesn’t work in the support forum. Trying again:
For example, if you registered your sidebar as follows, in functions.php:register_sidebar(array( // Above Posts widget area 'name'=>'sidebar-posts-before', 'description' => 'Area to display Widgets above Posts', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="title widgettitle">', 'after_title' => '</div>', ));
Then, you need to modify the appropriate template file so that before the Loop*, you call the following:
<?php if ( !dynamic_sidebar( 'sidebar-posts-before' ) ) { // Put any default (i.e. no-Widget) output here } ?>
* Note: The start of the Loop looks something like this (perhaps in index.php, or loop.php, etc.):
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
If you want this widgetized area to appear before *all* Posts, then, it should go immediately before the line above, e.g.:
<?php if ( !dynamic_sidebar( 'sidebar-posts-before' ) ) { // Put any default (i.e. no-Widget) output here } if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
very nice !!! thank you so much
how i can style this new sidebar in style.css?
what its div id that i can style it in style.csswhat its div class that i can style it in style.css
please help me i am new in wp
thanksDo you want to style the sidebar, or the Widgets within the sidebar?
I would recommend viewing source in your browser, to get an idea of what your various container classes are.
I want to stle the sidebar
this code is my template soure in browser iwant to style the new sidebar widget-before-pos(i rename it ‘omid’ ) like the left sidebar. thank you for your reply
[Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]
- The topic ‘How to add a widget top of the posts’ is closed to new replies.