Posted By

lromak on 10/15/10


Tagged

wordpress widget


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bobbym245
booski


Customizing Post Sort Order Using the Category Posts Widget


 / Published in: PHP
 

URL: http://www.moongoosedesigns.com/customizing-post-sort-order-using-the-category-posts-widget/

Edit widget or display current category in sidebar.php

  1. // Get array of post info.
  2. $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . '&orderby=date&order=asc');
  3.  
  4. 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:
  5.  
  6. <?php
  7. $sidebar_related_query = new WP_Query('cat=' . $sidebar_cat_id . '&showposts=5&offset=0&orderby=post_date&order=desc');
  8. while ($sidebar_related_query->have_posts()) : $sidebar_related_query->the_post();
  9. $do_not_duplicate = $post->ID;
  10. ?>
  11.  
  12. <div id=‚ÄĚpost-<?php the_ID(); ?>">
  13. <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
  14. </div>
  15.  
  16. <?php endwhile; ?>

Report this snippet  

You need to login to post a comment.