WordPress: Get page

There are a few WordPress functions to get specific page.

By page id

get_page() – Personally this is not my preference as you need to keep track of pages with its corresponding id’s.

By title

get_page_by_title() – The title will match as case insensitive. This is good when the title is short.

By slug

get_page_by_path() – This uses the string automaticaly formatted in permalinks and can be customized if required. Peronsally this is my preference simply because it looks better in codes.

Generic function

An alternative way is call a generic function query_posts() in the loop:

<?php query_posts('pagename=slug') ?>
.... do whatever template formatting here ....
<?php wp_reset_query() ?>

Note line 3: from wp_reset_query(), ‘This function destroys the previous query used on a custom Loop’.

Leave a Reply

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