jamieb7210
Member
Posted 9 months ago #
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?
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 }?>
jamieb7210
Member
Posted 9 months ago #
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.
jamieb7210
Member
Posted 9 months ago #
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?