• Hi.

    I have two feeds on one of my pages. I want both of them to display posts from different categories. I’ve tried researching and implementing a few differing codes and can’t get it to work with my current code.

    I’ve listed the code I’m using to call the loop bellow.

    <?php
    $args = array( 'numberposts' => 5, 'order'=> 'DESC', 'orderby' => 'date' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?> 
    
    	<h9><a class="postname" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
      <p class="date"><?php the_time('F jS, Y') ?></p>
    
    	<?php the_excerpt(); ?>
    		<hr class="postbreak">
    <?php endforeach; ?>

    Your help would be greatly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • In your code, you did not write anything to specify the categories. You can set the category id as a parameter for get_posts() function, see here

    So you have to repeat the code twice if you need to show posts from those categories separately. ie

    for 1st category posts:-

    $args = array( ‘numberposts’ => 5, ‘order’=> ‘DESC’, ‘cateogry’=>XX ‘orderby’ => ‘date’ );
    ——-here comes the rest of the code above—-

    For 2nd category:-
    repeat the code by changing the category ID specified (here I gave it as XX) in $args.

    In effect the change comes only in the $args.

    Thread Starter rmetfd

    (@rmetfd)

    Thanks for that!

    It didn’t work initially but I added a ‘,’ after ‘XX’ and it worked

    IE –

    $args = array( 'numberposts' => 5, 'order'=> 'DESC', 'cateogry'=> '1', 'orderby' => 'date' );

    Ohh, yes it was my mistake. Anyway glad to here that you could solve it. 🙂

    Thread Starter rmetfd

    (@rmetfd)

    Thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display posts from Category’ is closed to new replies.