I want to display posts on my wordpress site on the front-page.php template. How do I make this possible without having it as a static page..?
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php if( is_home() ) : ?>
<?php get_template_part( 'content' ); ?>
<?php else : ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endif; ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
Easy to go :) This one will add a list of 5 posts (read the inline marks) with title und shortdescription (if you set the readmore tag to your posts)
<ul>
<?php $the_query = new WP_Query( 'showposts=5' ); ?> <!-- change the number "5" to the number of posts you want to display -->
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_excerpt(__('(weiterlesen)')); ?></li> <!-- change "weiterlesen" to the value you want to display as "read more..." -->
<?php endwhile;?>
</ul>
OR this one will show the full content AND display a readmore tag if set it.
<ul>
<?php $the_query = new WP_Query( 'showposts=5' ); ?><!-- change number of posts to be displayed here -->
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_content(__('(weiterlesen)')); ?></li><!-- change the "read more" value by changing "weiter lesen..."
<?php endwhile;?>
</ul>
Or as the third option - the following will add a title per post with an excerpt limited to 200 characters if you didnt set the readmore tag.
<ul>
<?php $the_query = new WP_Query( 'showposts=5' ); ?><!-- change the number of posts here again -->
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php echo substr(strip_tags($post->post_content), 0, 200);?></li><!-- change the 200 to the number of characters you want to display -->
<?php endwhile;?>
</ul>
Hope this one will solve your problem.
All the best Fabian
add WP_Query
for get posts in any page.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array( 'post_type' => 'post', 'paged' => $paged,'posts_per_page' => get_option('posts_per_page')));
add this code below while loop you get all posts. user wp_reset_postdata();
& wp_reset_query();
for reset that query.