WordPress.org

Support

Support » Themes and Templates » Question about wp_get_archives() abilities

Question about wp_get_archives() abilities

  • I’m using the wp_get_archives(); template tag to retrieve a list of the 10 most recent posts for a sidebar on a theme I’m building. I’ve read through the documentation, but I can’t find answers to two questions. I’m currently using this code:

    ‘<?php wp_get_archives(‘type=postbypost&limit=10’); ?>

    So, it’s pulling in the last 10 posts. But I only want it to pull in from a specific category AND I want to display the date along with the title of the post. I can’t find any arguments to use to in the template tag to accomplish this. For instance this doesn’t work in trying to pull posts from a certain category:

    <?php wp_get_archives(‘type=postbypost&limit=10&category=”music”‘); ?>

    Is either one (or both) of these things possible? Any help or advice would be greatly appreciated. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Jeremy Clark

    @jeremyclark13

    Member

    You’ll probably have to do a mini loop in the sidebar.
    http://codex.wordpress.org/Template_Tags/query_posts
    Has what you need.

    Thank you very much, I’ll take a look at that.

    Perfect! That was exactly what I needed, thank you very much. Works great.

    Could I see the code you used to do that? I looked at the mini loop link and couldn’t make sense of it.

    Here’s what i use in my sidebar (although i offset the posts, i removed that for this example).

    <ul id="recent">
    <?php $posts = get_posts('numberposts=5');?>
    <?php foreach ($posts as $post): setup_postdata($post); ?>
    	<li<?php if($currentpost == $post->ID) echo ' class="current"'; ?>>
    		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach; } ?>
    </ul>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Question about wp_get_archives() abilities’ is closed to new replies.