[Resolved] Display specific content category on homepage w/

Home Forums Support [Resolved] Display specific content category on homepage w/

Home Forums Support Display specific content category on homepage w/

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2152653
    Scott

    Hi there,

    I’m wanting to create a homepage which using content templates in order to make a “cards” kind of style. Basically the exact same as the “Charge” theme – text on top of image.

    Only thing is, I don’t want ALL posts to show, just posts within 1 category.

    Is that possible?

    Thanks!
    Scott

    #2152762
    David
    Staff
    Customer Support

    Hi there,

    are you going to want another page that shows the entire blog ?

    #2153065
    Scott

    Hi David,

    No, that’s not desired. Just this one page that shows all posts with the specified tag (I said category earlier, but I meant tag).

    Thanks,
    Scott

    #2153071
    David
    Staff
    Customer Support

    OK, then you can add a PHP Snippet to your site:

    add_action( 'pre_get_posts', function ( $query ) {
        if ( !is_admin() && $query->is_home() && $query->is_main_query() ) {
            $query->set( 'tag', 'your_tag_slug' );
        }
    });

    Just update your_tag_slug

    #2153089
    Scott

    Thank you David. I’ll give this a try but, apologies for my ignorance – which PHP file would I be updating?

    #2153101
    David
    Staff
    Customer Support

    Sorry my bad – I should have explained = see this doc:

    https://docs.generatepress.com/article/adding-php/

    TLDR:
    If you have a Child Theme installed then: add it to the Child Themes functions.php. If you DO NOT then install the Code Snippets plugin and add it the code in a new Snippet.

    #2153137
    Scott

    Works!

    Thanks so much :))

    #2153163
    David
    Staff
    Customer Support

    Glad to hear that!!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.