- This topic has 8 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
January 7, 2023 at 5:25 am #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 } ?>January 7, 2023 at 6:34 am #2486894David
StaffCustomer SupportHi there,
no errors showing on the front end when you add the code ? ?
January 7, 2023 at 7:04 am #2486925Jack
No, nothing.
January 7, 2023 at 7:09 am #2486932David
StaffCustomer SupportAs its hooked outside of the loop, try adding:
global $post;at the top of the code.
January 7, 2023 at 7:11 am #2486935Jack
No luck I’m afraid. I also chose Before and After Entry Title and more.
January 7, 2023 at 7:12 am #2486938Jack
Here is a screenshot: https://i.imgur.com/YOEo1Ts.jpg
January 7, 2023 at 7:15 am #2486945Jack
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.
January 7, 2023 at 7:25 am #2486960Jack
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.
January 7, 2023 at 7:46 am #2486981David
StaffCustomer SupportOh 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 !! -
AuthorPosts
- You must be logged in to reply to this topic.