1

I'm developing a site that has about 200-300 pages, that each needs a custom side-menu, linking to primarily internal pages. So here's one sidebar:

  • Link to /foo
  • Link to /bar
  • Link to www.example.org

While another sidebar might have this structure:

  • Link to www.example.org
  • Link to /bar
  • Link to /foobar
  • Link to www.example.org/ex

So what's the best way to do this?


Current preferred: Using ACF?

Even though that Gutenberg is just around the corner, then it was possible to create an ACF-field, that is just a regular WYSIWYG-editor, as an extra field in the post. And then if it was blank, then it'd inherit the navigation from it's parent.


2nd best option: Using menus?

If I used menus, then I would have to created 200-300 'display locations' in my functions.php-file. And it would be a mess, matching the correct menu with the given page. So I assume this isn't the best way to do it.


3rd best option: Using a plugin?

I looked around, but couldn't find anything for this.


I can't use widgets, since it would mean a widget per post, which would be a mess.

Any suggestions? Or are ACF really the best choice?

4
  • 1
    It will be a mess no matter what, those are a lot of menus/pages. Commented Aug 18, 2018 at 18:13
  • I don't understand "linking to primarily internal pages.". can you edit your question to add a example ?
    – Kaperto
    Commented Aug 18, 2018 at 19:57
  • 1
    Are the pages being listed only child pages of a parent page? If they were arranged logically like that in the admin then you could generate the menu programatically. Commented Aug 19, 2018 at 3:37
  • 1
    If the links are completely random (custom for each page), then the best option is to do it with custom fields and then creating templates based on those custom fields. On the other hand, if the links have a well defined structure, then it's easy to implement with either a filtered menu or a widget.
    – Fayaz
    Commented Aug 19, 2018 at 17:49

1 Answer 1

0

If I understand your question right, here is the code to show the list of page siblings (having the same parent). Call the function from the sidebar.

<?php
function show_page_siblings( $id ) {

    $parent_id = wp_get_post_parent_id( $id );

    // show only on child pages
    if( 0 == $parent_id ) {
        return;
    }

    $siblings = get_pages( array(
        'child_of'     => $parent_id,
        'hierarchical' => 0,
        'parent'       => $parent_id,
        'post_type'    => 'page',
        'post_status'  => 'publish'
    ));

    if( !empty( $siblings ) ) {
        echo '<ul>';

        foreach( $siblings as $sibling ) {
            echo '<li><a href="' . get_permalink( $sibling->ID ) . '">' . $sibling->post_title . '</a></li>';
        }

        echo '</ul>';
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.