• 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

Education Pro – limit front page to 3 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 › Education Pro – limit front page to 3 categories

This topic is: resolved

Tagged: categories, education pro, front page, limit

  • This topic has 4 replies, 2 voices, and was last updated 5 years ago by carrie.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • January 28, 2018 at 11:36 pm #215810
    carrie
    Participant

    Hi there - I'm updating from Education to Education Pro. In the functions.php Education Theme I coded a limit of 3 categories on the front page. When I put the code in the functions.php Education Pro Theme, it doesn't work. Help please? I have:

    /**

    * Limit homepage to three categories

    *

    */

    function be_home_query( $query ) {

    if( $query->is_main_query() && $query->is_home() && !is_admin() )

    $query->set( ‘category_name’, ‘upcoming-events, news, member-messages’ );

    }

    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    Thanks,
    Carrie

    https://www.emscc.ca/pcc2018
    January 29, 2018 at 9:20 am #215820
    Victor Font
    Moderator

    is_home() returns true when a static page is set to display posts. If you are using a widgetized front page, is_home() is false. Use is_front_page() instead. Better yet, consider both ( is_home() || is_front_page() )


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 29, 2018 at 9:55 am #215824
    carrie
    Participant

    Thanks Victor, would this then be correct?

    /**

    * Limit homepage to three categories

    *

    */

    function be_home_query( $query ) {

    if( $query->is_main_query() && $query->( is_home() || is_front_page() ) && !is_admin() )

    $query->set( ‘category_name’, ‘upcoming-events, news, member-messages’ );

    }

    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    January 29, 2018 at 9:59 am #215825
    carrie
    Participant

    Okay, that's not working... I'm not sure what I need to be changing here?

    Thanks,
    Carrie

    January 29, 2018 at 9:11 pm #215865
    carrie
    Participant

    Okay, figured it out... that code didn't do anything. What I wanted was to exclude categories...

    function nice_exclude_cat( $query ) {

    if ( $query->is_home() && $query->is_main_query() )

    $query->set( 'cat', '-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-32,-33,-34,-35,-36,-37,-38,-39,-40,-41,-42,-43,-44,-46,-47,-48,-51' );

    return $query;

    }

    Yay! 🙂

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 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

© 2023 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