First question on here. I am doing a custom WordPress
site and I need to divide the post page (single.php) so that if it is a child of my WORK page it displays a certain HTML, else it displays another chunk of HTML.
At the moment I have the following inside the single.php
file:
<div class="work_section">
<p>WORK SECTION GOES HERE</p>
</div>
<!--div:work_section -->
<div class="news_section">
<p>NEWS SECTION GOES HERE</p>
</div>
<!--div:news_section -->
i am trying to tell it to display one if it’s a child of WORK page, or else the other div… how would I go about doing this?
Many thanks
Try this.
You can simply hide/show div elements, for example, on a button click. If you have two buttons with a data attribute, you can easily switch between these two pages. Buttons HTML:
And the jQuery:
But it can be more precise and readable if you use a section element insted of a div, with shorter class names like “news” and “work”. Then your jQuery code will be shorter:
There are several ways of doing this in wordpress.
or:
But I am not quiet sure if thats the best way to go about it. Maybe you should rethink how you are are modelling the site.
I would suggest to create 2 different custom post types, work & news. This way you can create instances or posts for each type e.g. single-work.php or single-news.php.
Codex: Custom Post Types
Another way would be to make WORK a category and do custom loop/query and/or conditional statements.