0

I am not so good with PHP and I have a bunch of codes that also involves wordpress codes.

I came up with these codes and it doesn't seem to work and I can't find a flaw since my knowledge on PHP and WordPress is not that great

<?php 
if ($page < "1") {
$page++ = $epone 
<strong><p>
  <span style="float: right"><a href="'<?php echo get_permalink().($epone++); ?>'">Next Page ▶▶</a></span></p></strong>
}
else {
<strong><p>
  <span style="float: right"><a href="'<?php echo get_permalink().($page++); ?>'">Next Page ▶▶</a></span>
<span style="float: left"><a href="'<?php echo get_permalink().($page--); ?>'">◀◀ Previous Page</a></span></p></strong>
}
?>

Thank you for Helping me out! This topic/question can also be used as a reference for Custom linking of Pagination (I know there is a separate code for single post pagination but please help me with the above codes, that's all I ask.)

  • Hey! I tried to fix the code block in your question, but I'm not sure I can fix the formatting any further, can you edit your question and use the code block button? Code blocks on Stack Exchange are indented by 4 spaces with blank lines above and below – Tom J Nowell May 13 '18 at 20:45
  • Thank you so much @Tom J Nowell Is the problem only because of Indentation for the codes? I didn't know identation is relevant to PHP. – Edogawa Kudo May 14 '18 at 2:50
  • I mean, your attempt to embed your code inside your question failed, and I have no idea which parts are your code, and which parts are attempts to format the question with HTML tags. Please edit your question so that it displays correctly. Additionally, if you have any error messages, post those too in quotes – Tom J Nowell May 14 '18 at 22:43
1

I see that you try to make some buttons with the links of the previous and the next publication, wordpress has many ways to get those links with functions, I will show you 4:

// You are two functions print a tag with its respective link

// Previous publication
get_previous_post_link();
// Next post
get_next_post_link();

With this function you get the WP_Post object of the previous and next publications and you can get the URL easily in this way:

// get the previous WP_Post object
$prev = get_previous_post();

// get the previous WP_Post object
$next = get_next_post();

// With the function get_permalink () and passing the property ID of the
// variable $prev or $next that have the object, we retrieve
// the URL of the previous or next link.

echo get_permalink( $prev->ID );
echo get_permalink( $next->ID );

Examples of use:

echo '<a href="' esc_url( get_permalink( $prev->ID ) ) . '">Previous Post</a>';
echo '<a href="' esc_url( get_permalink( $next->ID ) ) . '">Next Post</a>'; 

I hope this is what you need.

https://developer.wordpress.org/reference/

  • Rodriguez This totally not what I asked for and even if you didn't correct my code, you did not take into consideration that I am talking about "single post pagination" mentioned in my question. But I prefer that you would help me with my code rather than making your own answer for another question. – Edogawa Kudo May 14 '18 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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