Site logo

[Support request] Adding next previous buttons for (sub)pages not working

Home Forums Support [Support request] Adding next previous buttons for (sub)pages not working

Home Forums Support Adding next previous buttons for (sub)pages not working

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2486840
    Jack

    I have this code that used to work in the older version of the website, but I’m having difficulty to get it to work in GP.

    It used to be inside page.php in the old theme, but I now added it using a hook element, execute PHP checked and the hook location I varied just to be sure I wasn’t making a stupid mistake (after header, before content, before main content etc.), and the display rule set to alle pages or entire site, nothing works. Adding a simple echo ‘hello’ works, so that is okay. The ID’s of the pages inside the code have not changed.

    It should be visible on a subpage like this one: https://www.ullstorp.se/activities-available-here-or-near-ullstorp/swim-and-sunbathe-here-at-ullstorp/?lang=en

    <?php
    $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
    $pages = array();
    foreach ($pagelist as $page) {
       $pages[] += $page->ID;
    }
    
    $current = array_search($post->ID, $pages);
    $prevID = $pages[$current-1];
    $nextID = $pages[$current+1];
    ?>
    
    <?php
    if ( 5133 == $post->post_parent || 5135 == $post->post_parent || 6250 == $post->post_parent || 6252 == $post->post_parent || 6251 == $post->post_parent) {
    ?>
    
    <div class="navigation">
    <?php if (!empty($prevID)) { ?>
    
    <div class="previous">
    <a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>"><?php echo get_the_title($prevID); ?></a>
    </div>
    
    <?php } if (!empty($nextID)) { ?>
    
    <div class="next">
    <a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?></a>
    </div>
    
    <?php } ?>
    </div>
    
    <?php } ?>
    #2486894
    David
    Staff
    Customer Support

    Hi there,

    no errors showing on the front end when you add the code ? ?

    #2486925
    Jack

    No, nothing.

    #2486932
    David
    Staff
    Customer Support

    As its hooked outside of the loop, try adding:

    global $post;

    at the top of the code.

    #2486935
    Jack

    No luck I’m afraid. I also chose Before and After Entry Title and more.

    #2486938
    Jack

    Here is a screenshot: https://i.imgur.com/YOEo1Ts.jpg

    #2486945
    Jack

    When I uncheck ‘Execute PHP’, the content is displayed in the website at the right place, otherwise the code isn’t even visible in the source.

    #2486960
    Jack

    I just deactivated the Kadence Blocks plugin, saw that the links are on the website, then reactivated that plugin again and the links are still there! Seems to be working now, although I have no idea what deactivating and reactivating did.

    #2486981
    David
    Staff
    Customer Support

    Oh wow, that is very peculiar – i wonder what Kadence is doing that would mess with that.
    But i am glad to hear you got it working !!

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