Having created a central references page I need to place a link to the page on each page – this could be achieved by pasting a sentence and a link into each created page. This is a somewhat clunky solution and requires me to manually paste the information.
So, how can I get a link to the references on every page?
- A menu with a link to the references page.
- Edit the page template to include a link to references in every post.
- Put the link in a widget (either plain HTML or some other form).
The easiest way is to create a menu with a link (option 1), but in the interests of learning I will attempt to edit the page template – this does not negate having more than one of the options visible on the page.
The one sticking point for the page template method is that it will edit only my current theme (Hayley) – if I later decide to change it, I’ll have to update the page template on that theme. I am unsure if there is a way of adding it in in such a way to keep it permanently.
To see and edit the code behind the pages first click on ‘Appearance’, then ‘Editor’. The templates are listed along the right-hand side.
The target is the ‘Single Post’ template. I’ve inserted a test paragraph (HELLO – THIS IS A TEST), just to see where the line will appear:
It shows up here:
I really want it to appear below the text, but above the comment section, so I moved the code below the <article> tag – this was incorrect and displayed below the comment reply section.
I then tried putting the line inside an echo statement inside the PHP. This also pushed the line to the bottom of the page, below the comments.
<?php while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', get_post_format() ); echo "<p> HELLO - THIS IS A TEST IN PHP</p>"; endwhile; // End of the loop. ?>
The ‘template-parts/content’ is the next target, that piece of code appears to put the article and the comments section on the page. A couple more tests have pinpointed the exact position as below the pagination section (PHP), but inside the div and the article tags. This then displays above the grey horizontal line at the bottom of the post.
The final piece of code added has been enveloped in comments to make the code easy to find again.
<!-- MICHAEL EDIT \--> <br/> <b>References</b> <p>Please find all references <a href="http://itsuite.it.brighton.ac.uk/me93/idm18/blog/index.php/references/">here</a>.</p> <!-- END MICHAEL EDIT \-->
I think this is quite a nice solution as it is very easy to update the link centrally. One issue is that the link also appears on the references page itself. This should be easy enough to fix with an ‘if statement’, conditional on not being on the references page. This will require some research in how to determine the page in PHP.
Please find all references here.