• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Display Latest Posts from Multiple Categories

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Display Latest Posts from Multiple Categories

This topic is: resolved

Tagged: Multiple Categories

  • This topic has 10 replies, 3 voices, and was last updated 13 years, 4 months ago by e96989955.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • December 26, 2012 at 10:22 pm #7645
    e96989955
    Member

    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 #7671
    nickthegeek
    Member

    This 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 #7835
    e96989955
    Member

    Currently 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 #7840
    e96989955
    Member

    Sorry, 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 #7841
    e96989955
    Member

    Urgh, 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 #8046
    RossTeasley
    Member
    This reply has been marked as private.
    December 28, 2012 at 6:38 pm #8047
    RossTeasley
    Member

    Minor 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 #8338
    e96989955
    Member

    Hi 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 #8345
    nickthegeek
    Member

    you will need to add a clear break after each row. The HTML is

    <br class="clear" />
    
    December 30, 2012 at 8:39 pm #8506
    e96989955
    Member

    Hi 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 #8509
    e96989955
    Member

    Sorry, my bad! I forgot to add backslashes before each double quote on the break HTML code.

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble