Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Load A Specific Page's Content (Using Slug or ID) WordPress

  • SOLVED

I'm trying to create an editable image header/banner area for a client. Basically, it will use a jQuery script to transition & scroll between any images that are in a specific div.

I'm sure this can be done by creating a new page, and using the WP media upload function to load in any/all banner images. Then I can call this page into my template and essentially just load it's content.

I don't know exactly how to achieve this. I think I should probably have a separate loop which calls this specific page using it's ID or slug.

Can someone help with an example of code to achieve this?

Answers (2)

2010-04-25

Monster Coder answers:

Loading any specific post/page is very easy. get_post() function returns an object containing almost everything about a post/page.

$post = get_post($post_id); //$post_id should contain the ID of any post/page

echo '<pre>';
print_r($post);
echo '</pre>';

Now you will see the information it returns.

showing title:
echo $post->post_title;

showing body:
echo $post->post_content;
<em>In Lew's example, the key is wrong.</em>

showing post date:
echo $post->post_date;

you will get details in the link given by Lew.

By default, get_post() returns an object. If you want to play with associative arrays, you may call the function this way:
$post = get_post($post_id,ARRAY_A);
then you can get values like this way:

echo $post['post_title'];
echo $post['post_content'];


Thanks

2010-04-24

Lew Ayotte answers:

There is a WP function called get_post that might work for you... you can get the post by post ID.

http://codex.wordpress.org/Function_Reference/get_post


<?php
$id = 7;
$post = get_post($id);
<h2>$post->post_title;</h2>
$post->content;
?>


Lew