• Hello,
    how can I display only one category on Front page?

    I tried to add function in functions.php –

    function my_home_category( $query ) {
     if ( $query->is_home() && $query->is_main_query() ) {
     $query->set( 'cat', '3');
     }
    }
    add_action( 'pre_get_posts', 'my_home_category' );

    but nothing… it doesn’t works.
    any ideas?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @tombstone_13,

    I hope you are well today and thank you for your question.

    Do you want to display only one category or the posts attached to that category on front page?

    Also could you please share me your site URL where it’s displaying so that i can help you to achieve it?

    Best regards,
    Vinod Dalvi

    Thread Starter Lasha Peikrishvili

    (@tombstone_13)

    Thanks for your answer @vinod-dalvi,

    Yes I want to display only one category posts on front page.

    site URL: https://qbq.ge

    Your shared site doesn’t list posts on the home page so are you referring any specific section on the homepage?

    If yes then could you please tell me which section you are referring on our demo site here https://colorlib.com/illdy/ as your site is in another language that i don’t understand?

    Thread Starter Lasha Peikrishvili

    (@tombstone_13)

    oh sorry,
    yes my site is on Georgian.

    In the “Latest News” section I want to display only one concrete category.
    Normally in that section is shown last 3 posts from all category but I want to display last 3 post from one concrete category.

    To achieve this you have to modify following query in the theme file /illdy/sections/front-page-latest-news.php by overwriting it in child theme.

    $post_query_args = array(
    	'post_type'              => array( 'post' ),
    	'nopaging'               => false,
    	'posts_per_page'         => absint( $number_of_posts ),
    	'ignore_sticky_posts'    => true,
    	'cache_results'          => true,
    	'update_post_meta_cache' => true,
    	'update_post_term_cache' => true,
    );
    
    $post_query = new WP_Query( $post_query_args );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Only one category on Front Page’ is closed to new replies.