Separating Posts from Pages in Wordpress

April 16th, 2008

I decided that what our wordpress-cross-CMS for Ocean Addict required was the ability to browse through the thousands of expected Pages (pages because of the fact they exist outside of the post timeline as a form of static content) forming the school listings via the inbuilt category system. This was easily achievable by creating a page template specifically for displaying a school listing with the Comments and Categories shown and by using the useful plugin Page Category Plus for replicating the Category selection interface in the admin (I was already aware that this was possible since Pages are simply Posts that are treated differently but still have all the same mySQL fields).

While this side of things worked exactly as expected it threw up a unique issue I hadn’t considered.

While viewing the Category through the file Archive.php, for example http://www.oceanaddict.co.uk/category/sailing-yachting-and-dinghy/ the pages were displayed in exactly the same form as posts which put simply was something I didn’t want to happen. I had to find a way that pages and posts could be displayed differently in the archive page.

Initially I would have thought this would be quite easy for wordpress since it sends other variables to the template like the_ID(); and the_author(); and even a promising-sounding is_page();, but after a LOT of searching I found there was no method of determining the page type value after the SQL statement had run from the variables sent by wordpress itself.

Eventually I came across the solution:

if ( $post -> post_type == 'page' )

So there we go, if you wish to differentiate between pages and posts in your template, this is the line to use.

Leave a Comment

Write your response to Separating Posts from Pages in Wordpress

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Add Add a Comment

About Me

I am a web designer/digital artist currently studying BSc Digital Art and Technology in Plymouth University. I have returned for my fourth and final year of the course following my year in an industrial placement with the web design company Neovirtua and my own freelance work.

So far I have developed a wide range of skills, from producing videos using 3D software to gaining an aptitude for learning numerous programming languages. This is all on top of my original enthusiasm for art and HTML.

Read more…

Featured Work

Puzzle Flash

Based on a couple of puzzles I received a long time ago, this flash generates a random puzzle and then jumbles the pieces up for the player to solve.

Puzzle Flash game mini screenshot The flash actionscript behind this is flexible enough to allow for any size puzzle to be created and jumbled as many times as I like. In addition to this, the difficulty of rotating pieces is also a feature.

Try out Puzzle Flash…

© Copyright 2005-2008 -- Simon R.J. Mutton, All Rights Reserved.