WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. maddysayz
    Member
    Posted 1 year 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;
    							//$arrange_cat[]=$cat_id;
    							//echo $cat_id."---".$first->ID."<br>";
    					}
    			}
    query_posts(array('post__in' => $post_ids));
    
    $countp=1;
    $nrows=1;
    $arrange=0;
    // loop
    while (have_posts()) : the_post();
    //whatever needs to be displayed
    enwhile;

    Hope to have a reply ASAP.

    Thank you in Advance.

    Regards,

    Maddy

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

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Here is a pastebin with sample code that shows how to sort posts in the order of the post__in array:
    http://pastebin.com/3vwiDSfb

  3. maddysayz
    Member
    Posted 1 year 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