WordPress.org

Ready to get started?Download WordPress

Forums

How to let the sidebar show last 5 post of each catagory? (4 posts)

  1. umberrella
    Member
    Posted 6 years ago #

    Hi all,

    Im working on a new site right now, and I would like to have the sidebar showing the last 5 posts of each catagory.
    I do not have knowledge to write php myself, that is why Im posting the question here.

    Situation: I have 3 catagories... which i I like to name with immediatly under the name, the titels of 5 last published blog

    Example

    catagory a:
    blog 5
    blog 4
    blog 3
    blog 2
    blog 1

    catagory B:
    ..

    etc.

    I changed the php in sidebar.php to this:

    <?php wp_list_categories('title_li'); ?>

    Because I dont need to have the number of total post of the catagories behind it.

    Does anyone know what I have to do to get this done??

  2. umberrella
    Member
    Posted 6 years ago #

    Ok I found this plugin:
    http://www.frucomerci.com/list-posts-by-category-plugin-for-wordpress/

    this is helpful for me... but I dont know how I can limit the links per catagory to only 5...

    Anyone know this??

  3. Joni
    Member
    Posted 6 years ago #

    Well all you had to do was go to the plugin page (the link you posted above) and READ THE COMMENTS. The answer is right there. Jesus.

    Is there a way to limit the number of posts under each category? For example, I want to list only the most recent 10 posts. Thank you. This is a very good plugin. Easiest to use and does what it promises.
    # Frucomerci
    November 17th, 2007 at 4:44 am

    If you want to have the recent 10 posts, you need to change the Sql query string,
    put this:

    If your plugin is for < 2.3

    $arcresults = $wpdb->get_results("SELECT *, COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select post_id FROM $wpdb->post2cat WHERE category_id =$posts->cat_ID) GROUP BY 1 ORDER BY post_date DESC LIMIT 0 , 10;");

    if is for => 2.3

    $arcresults = $wpdb->get_results("SELECT *, COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select object_id FROM {$tp}term_relationships, {$tp}terms WHERE {$tp}term_relationships.term_taxonomy_id =" . $posts->term_id . ") GROUP BY 1 ORDER BY post_date DESC LIMIT 0 , 10;");

    Should work!

    Learn to READ the documentation first.

  4. umberrella
    Member
    Posted 6 years ago #

    Thank you hunni, I guess you need your cup of coffee now ;)
    I'll serve you one!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags