Community Forums › Forums › Design Tips and Tricks › Display Latest Posts from Multiple Categories
Tagged: Multiple Categories
This topic contains 10 replies, has 3 voices, and was last updated by e96989955 5 months, 2 weeks ago.
-
AuthorPosts
-
December 26, 2012 at 10:22 pm #7645
Hi, I’m using the Expose theme and would like to display the 3 latest posts from each category on my home page like this site here: http://www.newlaunchguru.com
I think it’s a relatively simple feature but can’t seem to find a plugin or hack in the WordPress community. Can anyone help me?
December 27, 2012 at 8:30 am #7671This is a bit tricky. For you have to remove the standard loop by adding this code to the home.php file
remove_action( 'genesis_loop', 'genesis_do_loop' );
Then you have to make your own custom loop by using
add_action( 'genesis_loop', 'child_do_home_loop' ); function child_do_home_loop() { //change "x" to match your category ID $loop_args = array( 'cat' => 'x', 'posts_per_page' => 3 ); genesis_custom_loop( $loop_args ); //Change "y" to match your category ID $loop_args['cat'] = 'y'; genesis_custom_loop( $loop_args ); //repeat the last two lines for each category. }You will need to remove the pagination as well so also add this to the home.php file
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
December 27, 2012 at 9:47 pm #7835Currently my code in home.php looks like this
remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
add_action( ‘genesis_loop’, ‘child_do_home_loop’ );
function child_do_home_loop() {Echo “<h1>Heading 1</h1>”;
//change “x” to match your category ID
$loop_args = array( ‘cat’ => ’1′, ‘posts_per_page’ => 3 );genesis_custom_loop( $loop_args );
Echo “<h1>Heading 2</h1>”;
//Change “y” to match your category ID
$loop_args['cat'] = ’4′;genesis_custom_loop( $loop_args );
Echo “<h1>Heading 3</h1>”;
//Change “y” to match your category ID
$loop_args['cat'] = ’6′;genesis_custom_loop( $loop_args );
Echo “<h1>Heading 4</h1>”;
//Change “y” to match your category ID
$loop_args['cat'] = ’7′;genesis_custom_loop( $loop_args );
Echo “<h1>Heading 5</h1>”;
//Change “y” to match your category ID
$loop_args['cat'] = ’5′;genesis_custom_loop( $loop_args );
}
remove_action( ‘genesis_after_endwhile’, ‘genesis_posts_nav’ );
December 27, 2012 at 9:57 pm #7840Sorry, I post it thrice by accident and I can’t seem to find the ‘delete’ post button here..
December 27, 2012 at 10:00 pm #7841Urgh, my original question got eoverwritten by the code snippet I pasted somehow.
I tried to add a heading before displaying each category, but it turned out rather weird like this : http://www.thenewlaunchguru.com
My original intention is to have each category displayed in the next line. Some categories have 3 entries, whilst some is just 1 or 2. The rest are empty at the moment.
December 28, 2012 at 6:37 pm #8046This reply has been marked as private.
December 28, 2012 at 6:38 pm #8047Minor correction in NickTheGeek’s code above:
$loop_args = array( 'cat' => 'x', 'posts_per_page' => 3 );should read:
$loop_args = array( 'cat' => x, 'posts_per_page' => 3 );(without apostrophes around the category id value)… at least that’s was needed on my server. This applies to each line that sets the cat ID.
December 30, 2012 at 7:02 am #8338Hi Ross!
Thanks for your reply.
I think you misunderstood my question. What I wanted was for each category to be displayed in a new row in the grid layout for the Expose child theme that I’m using.Currently, if my category has less than 3 entries, it’ll be squashed side by side with the entries from the previous category.
December 30, 2012 at 7:48 am #8345you will need to add a clear break after each row. The HTML is
<br class="clear" />
December 30, 2012 at 8:39 pm #8506Hi nick, I get a HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request. when I insert the Break as an echo before each heading.
December 30, 2012 at 9:02 pm #8509Sorry, my bad! I forgot to add backslashes before each double quote on the break HTML code.
-
AuthorPosts
You must be logged in to reply to this topic.