WordPress.org

Ready to get started?Download WordPress

Forums

Can this be done with categories in WP (10 posts)

  1. FionaGilbert
    Member
    Posted 8 years ago #

    If you take a peak at this site's sidebar: http://www.beyondrobson.com/ you will see that in the sidebar they have a 'Recently In' section that lists categories with the 2 most recent posts for each category.

    Can this be done in WP and if so how would one do this?

    Thanks
    Fi

  2. pcarlow
    Member
    Posted 8 years ago #

  3. FionaGilbert
    Member
    Posted 8 years ago #

    Hmmm thanks for that but I don't think it will do what I need. This is how I would like it to look:

    Category 1
    Category 1's Most recent post
    Category 1's 2nd Most Recent Post

    Category 2
    Category 2's Most recent post
    Category 2's 2nd Most Recent Post

    etc.

    Any other options?

    Thank you

  4. FionaGilbert
    Member
    Posted 8 years ago #

    Anyone?

  5. moshu
    Member
    Posted 8 years ago #

    You could try to have different calls for that plugin with different tags for each category. Did you try it before saying "I don't think it will do what I need"...?

  6. FionaGilbert
    Member
    Posted 8 years ago #

    moshu, yes I did :) I just wondered if there was another way to do what I require and thus far have had no joy.

    Thanks

  7. Dgold
    Member
    Posted 8 years ago #

    There's a ton of threads on this forum asking this question... believe me, I've read many of them. It seems possible but I have not found 1 clear explantation of how.

    It shouldn't need a plugin, this can be done with the right PHP calls, I just don't know how. Basically you probably just need to write multiple loops, sorta like this

    LOOP1
    Call Only Category 1
    List 2 headlines
    END LOOP1

    LOOP2
    Call Only Cat2
    List 2 headlines
    END LOOP2

  8. Ming
    Member
    Posted 8 years ago #

    You've got the right idea DGold and you could do that (see Multiple Loops in the Codex for more info). But that's essentially what this plugin is doing - running mini loops with specific criteria.

    To get the result you want with the plugin just do this:


    <ul>
    Category One
    <?php c2c_get_recent_posts(2, "<li>%post_date%: %post_URL%</li>", "0000"); ?>
    </ul>

    <ul>
    Category Two
    <?php c2c_get_recent_posts(2, "<li>%post_date%: %post_URL%</li>", "0000"); ?>
    </ul>

    You'll need to replace "0000" with your category ID (check manage->category to find that). You can also change how the listings display. See the plugin homepage for more info on that.

  9. FionaGilbert
    Member
    Posted 8 years ago #

    Ming,

    Thanks for that and I understand what you say but I really don't want to manually code the categories in case I ever change them.

    I just thought that we would be able to create dynamically the categories and some recent posts from those categories.

    Can it be that hard?

    Thank you

  10. Ming
    Member
    Posted 8 years ago #

    Yup, kinda :-)

    The code you would need has to do two things. 1) Query the database for a list of all your categories and then 2) loop through that list and for each category do another query to get and display the two most recent posts.

    Whether it's difficult or not really depends upon how good you can code PHP. Ideally you'd want to create this as a plugin so you could just drop a quick get_recent_posts_from_categories() function in your sidebar.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.