- This topic has 5 replies, 2 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
November 28, 2022 at 2:32 am #2438515
igniteperth
Hi Folks, I am trying to generate a custom nav for custom post types that displays after content (generate_after_content) using html and php in a Hook Element.
The php echo statement for next_post_link will not display inside the html div it is written in.
Can you please clarify how Hook Elements render the code inside, or help me understand what I am doing wrong?
<div class="pagination-wrapper"> <!-- PREVIOUS POST --> <div class="prev-post"> <?php echo $previous_post_link->ID;?> </div> <!-- end previous --> <!-- NEXT POST --> <div class="next-post"> <?php echo $next_post_link->ID;?> </div> <!-- end next --> </div>November 28, 2022 at 6:19 am #2438837David
StaffCustomer SupportHi there,
The Hooks that GP provides in the Elements module don’t do anything with the content you add inside them. They’re just like a placeholder that you can inject code/content into.
I assume the function that is generating then
$previous_post_linkis already returning its results to the content hence it shows outside of your HTML.Can i see all of the code ?
November 28, 2022 at 5:05 pm #2440093igniteperth
This is the Hook Element
<?php if (isset($_POST['data'])){ $post_id = $_POST['data']; }else{ $post_id = ""; } $wp_query->is_single = true; global $post; $post = get_post($post_id); $next_post_link = next_post_link('%link'); $previous_post_link = previous_post_link('%link'); $prev_post = get_previous_post(); $next_post = get_next_post(); ?> <div class="pagination-wrapper"> <!-- PREVIOUS POST --> <div class="prev-post"> <?php echo $previous_post_link->ID;?> </div> <!-- end previous --> <!-- NEXT POST --> <div class="next-post"> <?php echo $next_post_link->ID;?> </div> <!-- end next --> </div>and this is what it creates:
<div class="inside-article"> <div class="entry-content"></div> //HOOK IS FROM HERE (generate_after_content) <a href="https://dev.fabmarion.com.au/projects/nola-avenue-scarborough/" rel="next">Nola Avenue, Scarborough</a> <a href="https://dev.fabmarion.com.au/projects/kirwin-street/" rel="prev">Kirwin Street</a> <div class="pagination-wrapper"> <!-- PREVIOUS POST --> <div class="prev-post"></div> <!-- end previous --> <!-- NEXT POST --> <div class="next-post"></div> <!-- end next --> </div> //TO HERE </div>I am trying to understand why the php renders outside of the html it is placed in. Any pointers appreciated.
November 29, 2022 at 2:31 am #2440605David
StaffCustomer SupportThe links are being output here:
$next_post_link = next_post_link('%link'); $previous_post_link = previous_post_link('%link');Both the
next_post_linkandprevious_post_linkdisplay the links.
See the codex for more info:https://developer.wordpress.org/reference/functions/next_post_link/
So you could just do this:
<div class="pagination-wrapper"> <!-- PREVIOUS POST --> <div class="prev-post"> <?php previous_post_link(); ?> </div> <!-- end previous --> <!-- NEXT POST --> <div class="next-post"> <?php next_post_link(); ?> </div> <!-- end next --> </div>November 29, 2022 at 8:40 am #2441384igniteperth
I am such a Muppet! I mistook next_post_link for get_…
TY!
November 29, 2022 at 8:43 am #2441391David
StaffCustomer Support🙂 Glad to be of help
-
AuthorPosts
- You must be logged in to reply to this topic.