Support » Fixing WordPress » Show archives of current post category only

  • Here is what I’m trying to do:

    If I am viewing a post in Category Apple, I would like the sidebar to display a list of posts, by title, ONLY in Category Apple. Likewise if I’m viewing a post in Category Orange, I’d like a list of other posts by title in Orange.

    I’m guessing I would use the wp_get_archives command for this, but I don’t see a way to include a “self-referencing” directive for the category.

    Any help from a coding master? πŸ™‚ Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • You should take a look at the conditional_tags in Codex.

    Thanks Moshu, that was a helpful article. However I don’t know how to use correct php code to get the category of the post.

    For example:
    } elseif (is_category()) {
    // we're looking at a single category view, so let's show _all_ the categories
    echo "<ul>";
    wp_list_cats ('optionall=0&sort_column=name&list=1&children=1&hierarchical=1');
    echo "</ul>";

    What code will get the category of the post currently being viewed? Is it: (<?php the_category_ID(echo); ?> ? If so, where does that go in the above argument?

    Thanks for any and all help!

    I am not a coder either, but I think it should be something like
    if (is_category(X))
    show stuff

    where X is the category ID#.
    Note: you can also use the title or slug – see on the same page in the Codex.

    Moshu, your code idea is pretty much what I’m thinking. Where I get stuck is in the “show stuff” part. The “stuff” I would like to show is [I believe] a get_archive function, to display the titles of posts in the same category X. However, I can’t figure out how to call a list of post titles based on the category ID of the post being viewed.

    I feel like I have tried just about everything!!

    OK, I’ve been working on this for literally hours. I honestly feel like I have tried every code snippet in the codex! So, either what I want to do is impossible, or the answer is so simple I’m going to slap myself on the forehead when one of the coding gurus clues me in.

    So, is it even possible to do what I’m thinking? I’m thinking it’s not… which is a bummer! Will mean back to HTML for me… πŸ™

    I should also note that the above code, is_category(x) displays the condition only on category archive pages. I am specifically interested in creating a condition that would occur on a single post (is_single) of a particular category.

    [Sorry for the multiple posts here; it’s sorta late and I’m trying to provide as much info on my problem as possible!!] Thanks again for any help!! πŸ™‚

    Hey, check out this topic:

    Moshu, THANKS!!! πŸ™‚ That looks really promising! I still need some code help to figure out how to arrange everything correctly, though.

    My guess:

    elseif(is_single(<?php global $post;
    $categories = get_the_category();
    foreach($categories as $category) {
    $cat = $category[0]->cat_ID;
    } ?> = **category#**)) echo('header**category#**');

    [where **category#** would be an actual integer.

    I’m not sure if that will work or not… I need a PHP reference book for this one! 😐

    I’m doing something similar in a sidebar using customizable-post-listings plugin with a conditional statement.

    I elaborate in the end of this post, and you might find other info here as well.

    Echozone, what you’ve done is great! Can you please share the plugin you used or the code? Pretty please?? Thank you!!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Show archives of current post category only’ is closed to new replies.