[resolved] Posts Order with Respect to Category (3 posts)

  1. maddysayz
    Posted 3 years ago #

    Dears, I am developing this website and there is a requirement of having one most updated post from 6 categories displayed on home page. That functionality has been taken care of. The issue is the order in which the categories should be listed along with their one latest post. Can you help me out here please with it.

    the code that displays the 1 post per category is given below. The order in which category should appear is 9,14,10,16,15,13:

    foreach( array(9,14,10,16,15,13) as $cat_id ) {
    					if ( $posts = get_posts(array('category__in' => $cat_id, 'numberposts' => 1)) ) {
    							//echo $cat_id;
    							$first = array_shift($posts);
    							$post_ids[] = $first->ID;
    							//echo $cat_id."---".$first->ID."<br>";
    query_posts(array('post__in' => $post_ids));
    // loop
    while (have_posts()) : the_post();
    //whatever needs to be displayed

    Hope to have a reply ASAP.

    Thank you in Advance.



    [ http://codex.wordpress.org/Forum_Welcome#No_Bumping - if it is that urgent, consider to hire somebody; http://jobs.wordpress.net/ ]

  2. vtxyzzy
    Posted 3 years ago #

    Here is a pastebin with sample code that shows how to sort posts in the order of the post__in array:

  3. maddysayz
    Posted 3 years ago #

    Thank you. I really hope that the code let me display 1 post in the order of category that i want. Hope the code that you given is what i need. Let me take a look at it and get back to you.

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic