Reputation: 59
First I should explain my site structure. I have WordPress pages (with each their own page-{id}.php
template to change what they look like), these are also the main pages on my website. Consider these an overview, so like a catalogue in a store (which my website is not, but it's a good comparison)
On these pages I show a list of links (to continue the metaphor, the products of that store) to other pages, when I click on one of these links I go to a new page with actual content (a detailed view of the product in our metaphor). These pages are WordPress posts and are influenced by the single_post.php
template.
Now the problem, for four out of five pages there is no problem and the single_post.php
template does a great job. But for the last page I wanted to go a different route, but I cannot change the contents of that page because if I do, I'd have to change the single_post.php
template file and break the other pages.
So here's my question, I'm aware of the is_home
function in WordPress and I was wondering if there is a way to check in the single_post.php
file which page I'm on and depending on if I'm on one of the four good pages or the one bad page, I show different content? (Basically is there something like the is_home
function where you change the "home" part to a specific name of a page?)
This doesn't have to be something specific like the is_home
, a regular javascript or something would work just fine too.
Upvotes: 1
Views: 64
Reputation: 1426
You can use is_single function like below to check you are in which post:
if(is_single(123)) // Here check if post id equal 123
// some code
if(is_single("My post") // Here check if post title equal My post
// some code
if(is_single("my-post-slug") // Here check if post slug equal my-post-slug
// some code
Upvotes: 1