2

I'm trying to help a friend get his site in order and he wants me to swap out the "services" posts on the front page with 4 specific posts. Thing is, I don't know the right way to do this dynamically. How do I call up the content of just the post id, the featured-image (with the right dimensions) and a short excerpt from the beginning of the post?

Any suggestions would be greatly appreciated; thanks.

2
  • You will need to add more detail. These posts, are they posts or custom post types, are services a category or a custom taxonomy...., Jun 7, 2014 at 7:16
  • They are a custom post type, I believe.
    – M. Sage
    Jun 8, 2014 at 7:36

1 Answer 1

1

I have not tested this but based on your question, this should get you on track:

<?php

$id = 4; // The Page or post ID
$page_data = get_post( $id );
$title = $page_data->post_title;
$content = $page_data->post_content;
$excerpt = substr($content, 0, 155);
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($id, 'thumbnail') );

?>

<div class="post">
<h1><?php echo $title; ?></h1>
<div class="featured"><img src="<?php echo $featured_image; ?>" /></div>
<p class="excerpt"><strong><?php echo $excerpt; ?></strong></p>
<p class="content"><?php echo $content; ?></p>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.