[Support request] Query loop for related posts title only

Home Forums Support [Support request] Query loop for related posts title only

Home Forums Support Query loop for related posts title only

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #2279712
    Adarsha

    Hey.
    I was using “wpshow posts” all over my website. But now since latest update have changed every page to use query loop and its working great.
    Only place I am stuck is one where I show only titles on sidebar.

    I will share all links in private info for you guys to check.

    Current issue:

    Now each title is taken as H2 or any other based on what i choose for title. While using wpshow posts each title was shown as “p. Have attached a page where Wpshowposts is being used so you guys can have a look.

    Now since it takes each as H2 or any other I choose, it is inheriting all paddings and other stuff from H2/other thus making the titles bold, large spaces above and below. Further, I also don’t want to confuse google by showing all these titles as H2’s and stuff.

    What is the possible solution for this?

    #2279733
    Ying
    Staff
    Customer Support

    Hi Adarsha,

    As you are already using GenerateBlocks, I would recommend using GenerateBlocks’s query loop block instead of the WP query loop block.’

    In that case, you will be able to choose p or div as the titles, and it will give you much more control over every aspect.

    For more info about GB query loop block: https://docs.generateblocks.com/article/query-loop-overview/

    #2286511
    Adarsha

    Yes that worked. Only issue is there is no option for “Open in new tab”.
    Now if anyone clicks on related post built with this, it leaves the current page.

    The query block title block from wordpress had that option. How can I make sure it opens in new tab?

    #2286781
    Fernando
    Customer Support

    Hi Adarsha,

    For now, you’ll need a filter to make them open in a new tab.

    First, you’ll need to add open-new-tab to the class list of the Grid Block. It’s in the advanced section of the block’s settings.

    Then, you’ll need to add a PHP snippet like this:

    function db_rerender_url_new_tab( $block_content, $block ) {
    	if(!is_admin()){
    		if ( ! empty( $block['attrs']['className'] ) && 'open-new-tab' === $block['attrs']['className']  ) {
    			$my_search='href="';
    			$my_replace='target="_blank" href="';
    			$new_content = str_replace($my_search, $my_replace, $block_content);
    			return $new_content;
    		} 
    	}
        return $block_content;
    }
     
    add_filter( 'render_block', 'db_rerender_url_new_tab', 10, 2 );

    Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

    Hope this helps!

    #2286958
    Adarsha

    You mean for the query loop block?

    #2286967
    Fernando
    Customer Support

    Good question. For the Grid Block within the Query Loop Block.

    #2287505
    Adarsha

    This worked for my sidebar. But it did not work for my related posts bar at the bottom of the page.
    Both have query loop from GB.

    The related posts block at the bottom also has another CSS class which was provided by you guys (To hide the post from same page).
    So 2 classes are there. WordPress suggested to add new css with a space between old one. So I have added like this my-class-name open-new-tab

    Any idea why it may not be working?
    Attached link to one of the post at the sensitive section.

    #2287537
    David
    Staff
    Customer Support

    Hi there,

    i do not see the open-new-tab class on that grid in the post you linked to.
    Can you double check that ?

    #2287629
    Adarsha

    Have attached a screenshot in sensitive section.

    #2287661
    Ying
    Staff
    Customer Support

    Can you try removing the my-class-nameclass?

    Does the my-class-name class trigger some JavaScript code?

    #2287664
    Adarsha

    https://generatepress.com/forums/topic/query-loop-2/

    Please check this for why I added myclass
    It hides the post from the page.

    #2287728
    Ying
    Staff
    Customer Support

    I see, but it should not conflict.

    Anyway, you can remove the open-new-tab CSS from the Grid block, add it to the imageblock (featured image) and the headline block (title).

    #2287986
    Adarsha

    That worked. Thank you 🙂

    It would be great if you guys can add this and also not showing same post as the page as default options for query loop. Atleast provide in settings.. Especially the open in new tab.

    #2288735
    Ying
    Staff
    Customer Support

    We have the exclude current post option available for GB pro, unfortunately, free GB users will have to use PHP code.

    But I agree the open in new window option should be available 🙂

    We’ll see what we can do!

    #2289174
    Adarsha

    I have GB pro.. How can I enable it without having to use PHP code?

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