Forum
Blog Archive Year in title
Similar to this code to get a blog tag into the <title> tag, how do I get the archive year?
elseif (perch_get('tag')) { echo '<title>Articles tagged with ';
perch_blog_tag(perch_get('tag'));
echo '</title>';
}
Do you have the year in the URL?
Yes, its blog/archive.php?year=2016
You can use
perch_get('year')
then.Thanks, I had tried using that but looks like I had error in the syntax when I was originally trying to figure it out (PHP not a particular strong point of mine)
This works
Thanks again
I've just tidied that up now to this
Be sure to HTML encode the values from the URL before writing them to the page. Otherwise anyone can inject code into your page by modifying the query string.
Thanks Drew, where would I do this? Can you give me an example?
This is really beyond the scope of Perch, but you can use
htmlspecialchars()
.https://php.net/manual/en/function.htmlspecialchars.php
Ok, as a heads up is this what you meant. It still outputs ok on the front end.
I can see that this produces the following (safe) result if you try to add some code to inject at the end of the string, correct?