Access post, page, category and author information in custom template page or embedded PHP script within WordPress

In a custom page you call as a template in WordPress, this is the standard way to access some of the information about the particular post or page being viewed.  This is possible by accessing the WordPress query object, which is already instantiated by WordPress in a global class called $wp_query.  There is much more information you can get from this object, by visiting WordPress.org.  Another interesting aspect of accessing the $wp_query object is that you can override many of the properties and methods within this class to alter the functions, data, and output of the containing page so you can tailor the page for further customization.

For custom pages, do not ever close your files with closing PHP tags with scripts. Please note that different WordPress themes like Genesis may have different functions that will either alter how you can access the $wp_query object and in some instances do not allow accessing it.

Aaron Belchamber has written 243 articles

Leave a Reply

Your email address will not be published. Required fields are marked *