I tried to add posts in middle of my homepage content
this is my code for front-page.php
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, this page does not exist.'); ?></p>
<?php endif;
$allPosts = new WP_Query('cat=5&posts_per_page=2');
if ($allPosts -> have_posts()):
while($allPosts -> have_posts()) : $allPosts -> the_post();
?> <div class="container">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<hr>
</div>
<?php
endwhile;
else:
endif;
wp_reset_postdata();
?>
What I got is like this
---header---
---html-content---
---list-of-posts---
---footer---
what I tried to get is like this
---header---
---html-content---
---list-of-posts---
---html-content---
---footer---
Is there a way to get list of posts in middle of html content?
You should put the content you want under the list of posts in a separate post the print it by the ID under the list of posts.
Something like:
$my_postid = 12;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
If you don't want the post to be with your regular posts, create a special post-type. You could use CPT ui for it.