Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #876833
    kkendall2010
    Participant

    I’d like to display only certain blog categories on my blog page of the website. I found on another thread to use

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

    and list the blog ID, which I think I found but I’m not sure why it’s not working.

    #876837
    kkendall2010
    Participant
    This reply has been marked as private.
    #877591
    Rupok
    Member

    Hi there,

    Thanks for writing in! I can’t check your site as it’s asking for authentication.

    To use the above code, make sure you are using Latest Posts on homepage and the category slug research exists.

    In other way, you can use Recent Posts element in Cornerstone and set the category.

    Cheers!

    #879967
    kkendall2010
    Participant
    This reply has been marked as private.
    #881140
    Rad
    Moderator

    Hi there,

    I checked and yes that code isn’t working or ineffective. Though, I like to directly check it too through hard coding. Would you mind providing your FTP login credentials as well?

    About your second question, do you wish your blog home page not be the home page? I mean, you wish to set a static page at your home page other than the blog page?

    Thanks!

    #882146
    kkendall2010
    Participant

    I don’t have FTP login’s, and that is correct. I want a static front page, with the blog page somewhere else only displaying one category. I have the blog page established, I just need to specify the category.

    #883132
    Jade
    Moderator

    Hi there,

    I’m afraid it would be difficult for us to sort the first item since we need to check the changes in the code you have added in the child theme.

    As for the second question you can create a page that will be your homepage then go to Settings > Reading then set a static page for the Front page displays

    Hope this helps.

    #1085269
    Sitegemz
    Participant

    Hello I’m trying to do the same thing and I used the shortcode [display-posts category=”directory” posts_per_page=”10″ include_date=”false” order=”ASC” orderby=”title”] to display specific blog categories but it doesn’t seem to be working. I also asked this in another thread but can’t seem to find that one. Sorry

    #1085964
    Friech
    Moderator

    Hi There,

    Please update your shortcode to this

    [x_recent_posts type="post" count="4" offset="" category="directory" orientation="horizontal" no_sticky="true" no_image="false" fade="true"]

    Make sure you put a correct value on category="" attribute.

    Thanks.

    #1087315
    Sitegemz
    Participant

    that works but it’s still not giving me the ability to order in “ASC” or apply pagination for multiple posts. There are some 130 posts categorized in alphabetical order & also in directory I want to show the complete list with pagination 10-15 per page in directory you can look here for the page itself. http://mtz.sitegemz.com/?page_id=430 Vs. what the short code has given me. http://mtz.sitegemz.com/?page_id=683. I tried using wordpress arguments for the shortcode but I’m assuming the arguments have somewhat changed with the x-theme

    #1087954
    Rue Nel
    Moderator

    Hello There,

    Thanks for the updates! Since recent post element is not working for you, we will go back to your original code. It is not working because you are suppose to insert a category ID and not the category name. Please check out this article and correct your code:
    https://premium.wpmudev.org/blog/one-category-wordpress-homepage/?tchv=b&utm_expid=3606929-72.AqocGS0YR5Gn_p3r6t6_AA.1

    Hope this helps.

    #1088044
    Sitegemz
    Participant

    thanks for the help

    #1088278
    Rue Nel
    Moderator

    You’re welcome! We’re happy to help you out.
    If you need anything else we can help you with, don’t hesitate to open another thread.

    #1091007
    Sitegemz
    Participant

    This worked like a charm but now I need to get them ordered in alphabetical order. This is code I used
    }
    function my_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘5’); } } add_action( ‘pre_get_posts’, ‘my_home_category’ );

    This is the code I found in the knowledge base:

    add_action(‘pre_get_posts’, ‘category_sort_by_title’);
    function category_sort_by_title($query) {
    $query->set(‘orderby’, ‘title’);
    $query->set(‘order’, ‘ASC’);
    }

    I tried stacking them however they pretty much blew up the site & I needed to upload a backup to get it working again. please advise & thank you for your assistance.

    #1091293
    Lely
    Moderator

    Hi There,

    We need to combine those functions into one. Please remove both code and then use this instead:

    add_action('pre_get_posts', 'category_sort_by_title');
    function category_sort_by_title($query) {
        if ( $query->is_home() && $query->is_main_query() ) { 
    	 $query->set( 'cat', '5');
        }
        $query->set('orderby', 'title');
        $query->set('order', 'ASC');
    }

    Hope this helps.

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