Customizing Post Sort Order Using the Category Posts Widget

I use the Category Posts widget on a lot of sites to show a list of post titles beneath a category name in the sidebar. It automatically displays posts in descending order from the most recent post to the oldest posts. To change this order, you need to edit the cat-posts.php file in the category-posts plugin directory in the plugins directory.

Here’s the line of code to change:

The Category Posts Widget is very good for showing a certain # of posts in a particular category using a widget that displays on every page. However, if you only want to show the posts for the current category in the sidebar, then add this code to your sidebar.php file:

[php]<?php
$sidebar_related_query = new WP_Query(‘cat=’ . $sidebar_cat_id . ‘&showposts=5&offset=0&orderby=post_date&order=desc’);
while ($sidebar_related_query->have_posts()) : $sidebar_related_query->the_post();
$do_not_duplicate = $post->ID;
?>

<div id=”post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</div>

<?php endwhile; ?>[/php]

I got this from: http://www.finaldesign.co.uk/blog/wordpress/displaying-the-latest-current-category-articles-in-the-sidebar.html

5 Responses to “Customizing Post Sort Order Using the Category Posts Widget”

  1. Ryan says:

    Thanks for the tip! I changed “date” to “title” and was able to sort alphabetically by post name, which is exactly what I needed.

    Do you know of any way to display the posts in a drop down list (rather than displaying as an unordered list) with this plugin?

  2. angela says:

    Hi Ryan,

    If you’d like to show posts as a drop down menu, you might try:

    http://www.dagondesign.com/articles/drop-down-post-list-plugin-for-wordpress/

    Angela

  3. bigliettaio says:

    Hi.
    I would like to customer wp_category_psot in the same way i set widget setting in Theme Options.
    I use Atahualpa.
    Now w_category_post in implemented only in posts belongin in that category. http://www.ilbigliettaio.it/category/eventi-sportivi/rugby/
    and its category child.
    Visiting that category you can see theme setting widget: i use only recent posts.

    best regards

  4. angela says:

    I updated the post above to include instructions for how to display the the latest posts of the current category in the sidebar.

    See original post from:

    http://www.finaldesign.co.uk/blog/wordpress/displaying-the-latest-current-category-articles-in-the-sidebar.html

  5. bigliettaio says:

    Hi Angela,
    and excuse for my last comment: i was a little tired and i do not realize that you solved my problem !
    Anyway i solved using conditional_tag in widget logic plug in.

    Another question:
    do you think i could limit number of listed post in a simple way?

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes