WordPress.org

Ready to get started?Download WordPress

Forums

Question about wp_get_archives() abilities (6 posts)

  1. backpages
    Member
    Posted 5 years ago #

    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!

  2. Jeremy Clark
    Moderator
    Posted 5 years ago #

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

  3. backpages
    Member
    Posted 5 years ago #

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

  4. backpages
    Member
    Posted 5 years ago #

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

  5. ch0p5
    Member
    Posted 4 years ago #

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

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic