WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 2 Posts With Separate Archives (8 posts)

  1. Swick
    Member
    Posted 2 years ago #

    I'm going to admit right now that I'm brand new to WordPress and trying to learn as much as I can, and I've been working for awhile trying to get this sorted out. There's a site I'm building where the customer is looking for 2 separate post pages, so I created a different category for each. I created a template page for each of these such that they will only display posts from their respective categories (using query_posts('cat=x')). The problem is that each of these sections need to have an archive which organizes by the year they were posted. I was able to place these archives by using

    <?php wp_get_archives('type=yearly'); ?>

    It seems to get the years, but if I click on the link it gives, they always default to archive.php and I can't seem to find a way to pass the category I need to this page. What I need is to make the year in the specific post pages to either go to archive.php and have the correct category showing for that year, or have a way such that each go to their own respective PHP archiving pages. Any suggestions or help on how to do this would be gratefully appreciated. Just a heads up, I'm new to posting questions as well, so please be patient with me :)

  2. Spike
    Member
    Posted 2 years ago #

    http://codex.wordpress.org/Conditional_Tags

    On your archive page, one possible solution could be something like this:

    Edit: screwed up the code, this might work better:

    <?php
    if ( in_category('fruit') ) {
    	//do fruit stuff
    } elseif ( in_category('vegetables') ) {
            //do veggie stuff
    } else {
    	// Continue with normal Loop
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    	// ...
    }
    ?>
  3. Swick
    Member
    Posted 2 years ago #

    That doesn't seem to work. Once the page starts using archives.php, then it pretty much forgets what category it's using. The wp_get_archives code creates the links by year, but permalinks changes it all to http://example.com/2012. So there doesn't seem to be anything sending the category along to the next page.

  4. wpismypuppet
    Member
    Posted 2 years ago #

    First off, if you are new to WordPress you're in for a rough time. You'll have to custom code a lot of what you're looking to do unless you use a plugin. Here's another post with some good info:

    http://wordpress.org/support/topic/query_posts-for-year-and-category-how-to-keep-it-dynamic?replies=10

    Special reference to http://sltaylor.co.uk/blog/wordpress-category-archives-by-date/ and the two plugins mentioned:

    http://wordpress.org/extend/plugins/wp-category-archive/
    http://wordpress.org/extend/plugins/category-based-archives/

    Hope this helps...

  5. Swick
    Member
    Posted 2 years ago #

    Thanks for the response. I'll just have to try and sort it out. I've tried looking for a plugin that might do the trick, but there doesn't seem to be a lot of options to do what I need. Is there anything you could suggest?

  6. wpismypuppet
    Member
    Posted 2 years ago #

    I'm confused... I thought the plugin I suggested:

    http://wordpress.org/extend/plugins/wp-category-archive/

    was exactly what you were looking for??? It's description is (note the bold):

    The WordPress Category Archive Widget Plugin displays a monthly or yearly archive of posts for one specific category. It is very similar to the WordPress Archive except that it just displays one specific category's posts, not all categories. It can be configured to either show a listing or a pulldown by month or year with or without post counts.

  7. Swick
    Member
    Posted 2 years ago #

    Oops, sorry about that. I think I've been staring at my monitor too long to have overlooked the link. Thanks again.

  8. Spike
    Member
    Posted 2 years ago #

    OK, I didn't quite get the problem the first time around...

    If those plugins don't work, I suppose you could try passing a session variable between your pages.

    Maybe this is an overly complex way of doing it, but when you're on the category x page, create a session variable to pass the category on to the archives page. Do the same thing for category y.

    Then when you're on the archives page, you could construct a custom query that would grab the category from that variable, limiting the posts that are displayed to the category page you came from.

Topic Closed

This topic has been closed to new replies.

About this Topic