[Support request] Right sidebar – Related posts

Home Forums Support [Support request] Right sidebar – Related posts

Home Forums Support Right sidebar – Related posts

Viewing 14 posts - 16 through 29 (of 29 total)
  • Author
    Posts
  • #2327900
    Fernando
    Customer Support

    Here’s an article you may refer to with regards to uploading screenshots: https://docs.generatepress.com/article/using-the-premium-support-forum/#uploading-screenshots

    #2327903
    eran
    #2327906
    Fernando
    Customer Support

    To clarify, is that screenshot from the “edit” page of best-camera-for-streaming?

    Can you try checking if its at the very bottom of the page under all the content?

    #2327908
    eran

    Found, it was under all the content thank you!
    how can I make related posts in the child pages that will show the sibling pages + the parent page?

    #2328274
    eran

    how can I make related posts in the child pages that will show the sibling pages + the parent page?

    #2328301
    David
    Staff
    Customer Support

    Hi there,

    you would need to custom code to do that. The Theme doesn’t handle that. And GenerateBlocks Query Loop cannot handle that either.

    WordPress has the wp_list_pages function you can use:

    https://developer.wordpress.org/reference/functions/wp_list_pages/

    Heres an example snippet that creates a [page_siblings] shortcode, which will show parent and sibling pages

    add_shortcode('page_siblings', function(){
        ob_start();
        global $post;
        wp_list_pages( array(
            'child_of' => $post->post_parent,
    	'exclude' => $post->ID,
            'depth' => 1
        ) );
        return ob_get_clean();
    });
    #2328317
    eran

    I dont know how to do that.
    Is this something you work on generateblocks?

    #2328330
    David
    Staff
    Customer Support

    GenerateBlocks can currently list Child Pages. In the future we may review and allow it to display Siblings.
    But if you want Parent and Siblings then the best method is the wp_list_pages function in WP.

    The code i provided above is a PHP Snippet. This doc explains how to add PHP:

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

    TLDR: Are you using a Child Theme?
    If Yes, then you add that code to the Child Themes functions.php
    If No, then install the code snippets plugin ( link can be found in the doc above ) and add New Snippet to add the code.

    With that code added, you can add a Shortcode block to your page and add [page_siblings] inside that block.

    #2328335
    eran

    And then i need to add the related posts block to that page? Or only the php code is enough?

    #2328486
    David
    Staff
    Customer Support

    No.
    You first add the PHP Snippet to your theme.
    Either in the Child Theme functions.php or Code Snippets.

    Then you just add a Shortcode Block and inside it paste: [page_siblings]

    Thats it.

    #2328733
    eran

    It worked but without the parent page.
    anyway to add the parent page?

    #2329126
    David
    Staff
    Customer Support

    What do you want to happen if you’re on the Parent page ?

    #2329171
    eran

    Parent page – related pages of all child pages. (Done with generatepblock).

    Child page – related pages of sibling + parent page. How can i do that?

    #2330242
    David
    Staff
    Customer Support

    Sorry i thought i had answered this.
    Change the shortcode snippet to:

    add_shortcode('page_siblings', function(){
        ob_start();
        global $post;
    	if ( $post->post_parent ) {
            echo '<a href="' . $post->post_parent . '" >' . get_the_title( $post->post_parent ) . '</a>';
        }
        wp_list_pages( array(
            'child_of' => $post->post_parent,
    		'exclude' => $post->ID,
            'depth' => 1
        ) );
        return ob_get_clean();
    });
Viewing 14 posts - 16 through 29 (of 29 total)
  • You must be logged in to reply to this topic.