Quantcast
Channel: David Orlo .com | Tag Archives: WP_Query
Viewing all articles
Browse latest Browse all 4

WordPress wp_get_archives from specific category ?

$
0
0
While trying to figure out how I could show posts from two categories but always keep one category on top I finally gave up. The best I could find was to run multiple custom queries using rewind_posts() but even this was difficult to carry from theme to theme as I changed my mind quite often.
What I finally decided on was to exclude specific posts on the home page while keeping my sticky at the top and in the side bar I would query post from a specific category. First I began searching how to use wp_get_archives to show posts from a specific category but later realized I was going about it the wrong way and needed to be using something a little more complex but was willing to bet I could find a good example and that I did. I will share the example with you here so you can modify it as I have to replace the customization lacking wp_get_archives function.

While trying to figure out how I could show posts from two categories but always keep one category on top I finally gave up. The best I could find was to run multiple custom queries using rewind_posts() but even this was difficult to carry from theme to theme as I changed my mind quite often.
What I finally decided on was to exclude specific posts on the home page while keeping my sticky at the top and in the side bar I would query post from a specific category. First I began searching how to use wp_get_archives to show posts from a specific category but later realized I was going about it the wrong way and needed to be using something a little more complex but was willing to bet I could find a good example and that I did. I will share the example with you here so you can modify it as I have to replace the customization lacking wp_get_archives function.

<ul>
<?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>

Viewing all articles
Browse latest Browse all 4

Trending Articles