Previous page : Programmering 1 - JavaScript
Next page : Previous Up Next - Pun
I wanted to add links to the previous and next pages at the same level. To start with I added the Next Page, Not Next Post plug-in. You can find information about the plugin at https://binarym.com/2009/next-page-not-next-post/.
I could then manually add [previous_page] and [next_page] anchor texts on each page, but that would take time, and would not be particularly flexible. What I did instead was to create a child theme, and in that, I added a filter to the functions.php file.
A filter is a process that a page has to go through before it is sent to the visitor.
In this case, I want the filter to add [previous_page] and [next_page] to the header and footer of the page, and also some vertical lines to frame the text. I also have a few pages where I don’t want this to happen. I add the tag [pnp] but with n instead of p and p instead of n somewhere at the beginning of such a page. (I am somewhat proud of that I thought of not writing the actual tag on this page.)
If such a tag is on the page it is overwritten, else texts are added at the top of and at the end of the contents. This is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ ); function theme_enqueue_styles() { wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ ); } add_filter(‘the_content’,’add_my_c1′); function add_my_c1($content) { $lineup='<a href=”http://media.properhoc.com/2017/01/lineup.png”><img class=”aligncenter size-full wp-image-391″ src=”http://media.properhoc.com/2017/01/lineup.png” alt=”” width=”654″ height=”3″ /></a>’; $linedown='<a href=”http://media.properhoc.com/2015/10/linelow.png”><img class=”aligncenter size-full wp-image-409″ src=”http://media.properhoc.com/2015/10/linelow.png” alt=”” width=”654″ height=”3″ /></a>’; $up_text = ‘Previous page: [previous_page] : Next page: [next_page]’.chr(0x0D).chr(0x0A).’ ‘.chr(0x0D).chr(0x0A).$lineup; $low_text = $lineup.chr(0x0D).chr(0x0A).chr(0x0D).chr(0x0A).’Previous page: [previous_page] : Next page: [next_page]’.chr(0x0D).chr(0x0A).$lineup.’Last modified: Jan 22, 2017 @ 17:55‘; $pos=strpos($content,'[pnp]’); if($pos){ $content =substr_replace($content,’ ‘,$pos,5); } else{ $content = $up_text.$content.$low_text; } return $content; } |
I also added a timestamp of the time of the latest change in the footer.
Up a level : ProgrammingPrevious page : Programmering 1 - JavaScript
Next page : Previous Up Next - PunLast modified: