Site logo

Archived topic

Right sidebar - Related posts

28 replies · Started by eran on August 29, 2022

Viewing posts 16–29 of 29

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?

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?

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

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();
});

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

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.

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

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.

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

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

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

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

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();
});
This archived topic is closed to new replies.