WordPress.org

Ready to get started?Download WordPress

Forums

Show archives of current post category only (12 posts)

  1. eveums
    Member
    Posted 8 years ago #

    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!

  2. moshu
    Member
    Posted 8 years ago #

    You should take a look at the conditional_tags in Codex.

  3. eveums
    Member
    Posted 8 years ago #

    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!

  4. moshu
    Member
    Posted 8 years ago #

    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.

  5. eveums
    Member
    Posted 8 years ago #

    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!!

  6. eveums
    Member
    Posted 8 years ago #

    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... :(

  7. eveums
    Member
    Posted 8 years ago #

    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!! :)

  8. moshu
    Member
    Posted 8 years ago #

    Hey, check out this topic:
    http://wordpress.org/support/topic/42803

  9. eveums
    Member
    Posted 8 years ago #

    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! :|

  10. echozone
    Member
    Posted 8 years ago #

    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.
    http://wordpress.org/support/topic/31686

  11. eveums
    Member
    Posted 8 years ago #

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

  12. HarryelSucio
    Member
    Posted 8 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags