tags:

views:

31

answers:

2

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>
  1. Is there a better / easier way?
  2. The output is striped for HTML. How can I maintain HTML?
+1  A: 

Well, if you can write the content as a page instead, you can do: Admin -> Settings -> Reading -> Front page displays -> A static page.

Adam Backstrom
It is static, otherwise I would not be able to add custom property to my index / startpage.
Steven
A: 

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.

Chad Birch
I am using page. And the text field is already used for the welcome message. Since it is not possible to have any more text fields that can take HTML formatting, I have to create a post with the opening hours.
Steven