• I am trying to display the parts of the_content (post title, post main body, feature image, and some custom fields) in a different order than they appear when using

    <?php get_template_part( 'content', 'single' );

    this is a custom post template; only in this category will the post information appear in this order. I know I can show the title of the post with
    <?php single_post_title(); ?>

    but how can I pull out the feature image and body copy and control where on the page those elements will go?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You use the loop just like any other post.

    <?php
    $args = array( 'post_type' => 'homepage', 'posts_per_page' => 1 );//Add as many perameters you need. 'post_type' is the name of your custom post type.
    $loop = new WP_Query($args);
    the_title(); //Get Your Title
    the_content(); //Your Content
    while ($loop->have_posts() ) : $loop->the_post();
    endwhile;
    ?>

    For Getting Features Image Use This
    <?php if(has_post_thumbnail()) { ?><?php the_post_thumbnail()?><?php }?>

    Thread Starter jamieb7210

    (@jamieb7210)

    That’s basically what I have right now. But the_content is pulling in the title, so what I have now is the title, the thumbnail, then the title again, the body, the meta etc. Is there a way to just get the body out of a post and not have to call the_content at all? or is there a better way to do this? i apologise I dont have much experience doing this.

    If your using headers in your post, then yes that will come out of it as well using the_content(); An easier way no, a more complex way yes.

    Thread Starter jamieb7210

    (@jamieb7210)

    ok, what is the more complex way?
    is there a way to write a new function that I can call, that excludes the title and meta perhaps?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display only specific parts of a post (or change their order)’ is closed to new replies.