• Hi,

    I am trying to show a list of the 10 most recent posts based on category in the sidebar.

    What I have works fine but wow it’s ugly. So I am sure there is a cleaner and better way.

    To do this I am currently using the Customizable Post Listings Plug-in:

    https://www.coffee2code.com/archives/2004/08/27/plugin-customizable-post-listings/

    And here is the current code:

    <!-- Start Custom Recent Posts - Shows Last 10 Posts Based on Category -->
    <h2>Recent Posts</h2>
    <ul>
    <?php if ( in_category(1) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "1", "date", "DESC", 0);} else if (in_category (2) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "2", "date", "DESC", 0); } else if (in_category (3) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "3", "date", "DESC", 0); } else if (in_category (4) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "4", "date", "DESC", 0); } else if (in_category (5) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "5", "date", "DESC", 0); } else if (in_category (6) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "6", "date", "DESC", 0); } else if (in_category (7) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "7", "date", "DESC", 0); } else if (in_category (8) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "8", "date", "DESC", 0); } else if (in_category (9) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "9", "date", "DESC", 0); } else if (in_category (10) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "10", "date", "DESC", 0); } else if (in_category (11) ) { c2c_get_recent_posts(10, "%post_URL%<br />", "11", "date", "DESC", 0); } else { echo 'Coming Soon';} ?>
    </ul>
    <!-- End Custom Recent Posts -->

    Any ideas on how to clean it up a bit?

    Thanks,

    Will

Viewing 16 replies (of 16 total)
Viewing 16 replies (of 16 total)
  • The topic ‘Show Recent Posts Based on Category’ is closed to new replies.