feed Posts (RSS | eMail)
feed Comments (RSS | eMail)
Loading in process - please be patient.

Please consider signing the Google Gmail Automatic BCC Option Petition
and spread the word. Thanks!

I need more signatures - at least, help me reach the 100 for starters! :-)
[click box to close]

For my own theme - which I am currently designing - I wanted the 5 most recent posts to be displayed in the right sidebar. So I tried to use the query_posts() template tag with the parameter ’showposts=5′.

Well, it worked for the sidebar - the only problem was: now each and every post was shown in the main section of the page, even if the URL pointed to just one single post! I tried to set back the parameters using $query_string, but that did not work.

That made me kind of wonder why it works in my current (alternated) MistyLook theme: I use the same method to display the 5 most recent posts in the sidebar - and it works fine!

I found out that - in the MistyLook theme - the sidebar is included AFTER The Loop, which means that the main section remains unaffected by calling query_posts(). In my own theme, the right sidebar is included BEFORE, and that means that it will also affect The Loop, i.e. the original query is lost - WordPress “forgets” that e.g. a single post is supposed to appear.

I did a Google search and happened to find the get_posts() template tag which does not change the SQL query and works fine.

I changed the code as follows:

<ul class="sidebox_ul">
<?php
     global $post;
     $recent_posts = get_posts('numberposts=5');
     foreach($recent_posts as $post) : ?>
          <li class="sidebox_li"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
</ul>

This works great!

I also looked for a similar tag for comments, but found none. So I think I will remain using the WP Plugin Recent Comments.

The post ends here. Wanna leave a response? Have Your Say!

Next post: WordPress Posting Issue Using “Div”-Tags
Previous post: Online Color Schemer By Adobe

Trackback URI | Comments RSS | Permalink

del.icio.us del.icio.us eMail this post eMail Print Print
Did you like this post? NoYes
No votes yet, be the first!
Loading ... Loading ...

Have Your Say!

back to top