Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1349554
    dundidandi
    Participant

    Hi There!

    I’m Daniel, a total-wp-dummie but very enthusiastic!

    I’m trying to set up the homepage of my website to show only one category of blog posts instead of all of them. I was looking for this option everywhere under the “customize” menu but couldn’t find the answer. I’ve read many forum posts as well without success (most are very difficult to me, codes etc.).

    I’m using the “Renew” stack of the X Theme.

    Could you help me with your advice?

    Warm regards,

    Daniel

    #1349601
    Thai
    Moderator

    Hi Daniel,

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please add following PHP code below into functions.php locates in child theme’s folder:

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

    The 123 number is your category ID.

    Hope it helps.

  • <script> jQuery(function($){ $("#no-reply-1349554 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>