• Resolved cmwagner

    (@cmwagner)


    (NOTE: I may be upgrading to 2.3.1 soon, but haven’t as of yet. My host will be upgrading it)

    I understand the concept behind wp_get_archives, but I’m not quite sure how to limit it to one category only. I’m working on a site that has only 2 categories, but 1 is for images only, and the other for your typical “blog” style posts. Obviously, I only want to list the typical “blog” posts.

    Any help would be useful!

    Thanks,

    Cat

Viewing 7 replies - 1 through 7 (of 7 total)
  • Is your problem that you don’t want the posts in the image category to show up on the archive page? If so, I’d suggest editing archive.php to use a call to in_category to “hide” the posts you don’t want to see.

    If the problem’s with the html output of wp_get_archives itself (for instance, you don’t want the post count to include the posts in the image category), it’ll be more complicated.

    Thread Starter cmwagner

    (@cmwagner)

    Actually, I want to set up a “Recent Blog Posts” section in the footer of the main index page.

    It doesn’t make sense to me that I can’t call for a particular category rather than generically posting everything.

    I’m having the same problem with trying to figure out how to set up things on the index page so that I can get the most recent image file to show up in my content area, while a “teaser” for the most recent blog posts shows up in the sidebar. I’ve already figured out that I need to do category-#.php pages for the separate archives.

    Since I’m new to WordPress, I’m still slogging through the lessons, but haven’t been able to truly find what I need.

    Cat

    wp_get_archives does NOT have a category parameter. For what you want you need some other methods: recent_posts plugin or custom mini-Loop.

    Here’s an example of a “custom mini-loop.” It’s the code I use to show recent posts in the sidebar (reformatted a bit and after removing the extra attributes on the <a> tag. If you’re putting this in the footer, you might not need to save off the page’s default query and restore it — but it’ll be needed to show the teaser in the sidebar or recent image in the main part of the page.

    The key part here is the use of query_posts. Check there for other parameters and several examples.

    <?php
      $include_cats = ... whatever makes sense here ....
      $temp_query = $wp_query;
      query_posts('showposts=5&cat='.$include_cats);
      while (have_posts()) {
         the_post();
    ?>
    <li>
      <?php the_time('m/d'); ?>:
      <a href="<?php the_permalink(); ?>" >
      <?php the_title(); ?></a>
    </li>
    <?php
    } // end custom loop
    $wp_query = $temp_query;
    ?>

    Best wishes as you work through the lessons. I’m afraid I wasn’t that methodical — mostly took it one template tag at a time. It took quite awhile before I had the sense that I could tweak WordPress to do what I wanted (mostly, anyway).

    There are, no doubt, plugins to do this, but when I can drop code onto a page, I prefer to do that. On the other hand, something like

    https://www.ads-software.com/extend/plugins/show-post-by-selective-category/

    may help you out if you’re not (yet) comfortable with the PHP.

    Thread Starter cmwagner

    (@cmwagner)

    Moshu, thank you. I tried the recent_posts plugin by Rob Marsh, and it works just fine.

    Hellooo, my first post here… Sorry to revive a thread that’s been dead 6 months ?? but the initial request, which is now my problem, is not really resolved…

    The custom loop with query_posts will get a list of chronological results stripped from all results from categories (or other) one would want to exclude; (my english is a bit clumsy sorry for that!)

    But we miss the possibility of calling all the archives of a single category, or all possible links to posts in this category, arranged by months or years…

    Any idea? Maybe some extra functions plugged into the loop that would make it behave like the regular wp_get_archives, but for only ONE single category?

    I’m loving WP every day a lil bit more ??

    I’m trying to do the same thing.

    I’ve created a category for image posts.

    I want the archive links to display posts purely from that single category.

    If anyone has any ideas, that would be much appreciated. ??

    I’m on 2.5

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp_get_archives – but only one category’ is closed to new replies.