[Resolved] Adding custom field to query loop for post summaries

Home Forums Support [Resolved] Adding custom field to query loop for post summaries

Home Forums Support Adding custom field to query loop for post summaries

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2203261
    eadcock

    My client would like to have the option to add a secondary title to their blog posts and have it visible under the post title on the summary pages. I was able to add it to the single post page via custom fields and a custom field element hook, but I’m unable to find how to add it to the summary pages. I’m currently using a query loop to bring in post summaries. I was trying the route of a block element with dynamic content, but for some reason dynamic content is not available on header or button blocks. Does it need to be activated somewhere?
    Your help is appreciated!

    #2203287
    Ying
    Staff
    Customer Support

    Hi there,

    but for some reason dynamic content is not available on header or button blocks.

    I’m not sure I fully understand this sentence, can you explain a bit more?

    If you are trying to add a block element with dynamic content to a query loop block in a static page, it’s not going to work.

    You can add block element to the default blog/archive page.

    #2203787
    eadcock

    Thanks Ying, The dynamic content I was referencing is in this article: https://docs.generatepress.com/article/dynamic-data/. So is there any way to add dynamic content to the query loop? The reason I’m not using the default blog/archive page is that I used the post element for job postings and team in addition to blog posts so the default blog/archive page pulls all that content. Is there a way to filter the default blog/archive page? That would be a solution as well.

    #2203799
    David
    Staff
    Customer Support

    Hi there,

    the GP Dynamic Data only works inside the Block Element.
    And to the best of my knowledge there is no open hooks for adding content to the Core Query Loop block. I am not sure if it even supports adding a Shortcode for other data.

    As a note we will be soon releasing GenerateBlocks 1.5 which will have dynamic data and its own Query Loop that will support some custom post meta.

    Using the theme templates – whats the current issue with blog/archive page ? is there a post type or category that you need to exclude ? Let me know.

    #2203805
    eadcock

    Thank you David,
    And you’re correct. I’m using the post function for multiple categories, so if there’s a way to filter the default blog/archive – and/or create multiple archives for different categories or post types – that would work.

    #2203811
    David
    Staff
    Customer Support

    So you can add the following PHP Snippet to exclude a Category from the Blog:

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

    the -22 is the ID of the Category you want to exclude ( if you edit a Category term, and look at the browser URL field it will show the ID=XX ).

    As its an array you exclude multiple categories if required eg

    $query->set( 'cat', array( -22, -33, -59 ) );

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

    In addition each category will have its own URL to display its archive page eg.:

    https://your-site.com/category/your-category-slug

    #2204220
    eadcock

    Thank you David!
    That worked famously

    #2204625
    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.