I have created a query to return 3 particular posts however at the moment they just appear with the three titles in a list as per the query on WP Codex.
I need them to show as per the blog section but am unsure as to where and how to call the template in. This is my code:
<?php
// The Query
$include_ids = array( '114', '115', '116' );
$query = new WP_Query( array( 'post__in' => $include_ids ) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
?>
Can anyone help me with this please?
You need to include the code to actually include the template you need. The details depend a bit on the theme, but is probably going to be something like:
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : ?>
<?php $query->the_post(); ?>
<?php get_template_part('content', get_post_format()); ?>
<?php endwhile; ?>
<?php endif; ?>
Wordpress templates use different template files for different parts of you site. Code that is in single.php
will be run when you open a single post in the browser. Code in category.php
will run when you open a category page.
It's not quite clear what you mean by "as per the blog section". If you still need more information, clarify your question and I will update my answer to let you know how to do it.