Reputation: 19425
I need to retrieve a specific post to display on my websites front page. To avoid hard coding the post ID, I've added a custom property where I add the post ID.
The following code displays the wanted post:
(The code is within the LOOP)
// Get content from specific post (in this case, Åpningstider post))
$openingHoursID = get_post_meta($post->ID, "apningstider", true);
if (!empty($openingHoursID))
{
$openingHoursPost = get_post($openingHoursID);
$openingHours = $openingHoursPost->post_content;
}
else
$openingHours = "Åpningstid ikke angitt";
<div class="openinghours"><?php echo $openingHours; ?></div>
Upvotes: 0
Views: 74
Reputation: 74558
You should consider putting this content in a Page instead of a Post, they're meant for this sort of thing.
But for what you're currently doing, you should just call query_posts()
before the loop with that particular post ID, like query_posts('p='.$openingHoursID)
and then use the_content()
as normal to output the post with formatting intact.
Upvotes: 0
Reputation:
Well, if you can write the content as a page instead, you can do: Admin -> Settings -> Reading -> Front page displays -> A static page.
Upvotes: 1