Okay So I want to create a Custom Page Template that displays my posts exactly the same as my index.php
does. You can see the code of my index.php
at the bottom.
So I create a .php file named customindex.php and use the exact same code of my index.php
and the code on the top to mark it as custom page template:
<?php
/*
Template Name: Custom Index
*/
Problem: The page with the Custom Index page template won't display any posts and I don't know why.
Code of my index.php
:
<?php get_header(); ?>
<h1 class="heading" style="width:100%"><?php _e( 'Beliebte Zitate', 'html5blank'); ?></h1>
<?php get_sidebar(); ?>
<section id="home">
<?php get_template_part('loop'); ?>
</section>
<div id="pagination">
<?php html5wp_pagination(); ?><br>
</div>
<?php get_footer(); ?>
Code of my customindex.php (nearly the same as index.php):
<?php
/*
Template Name: Custom Index
*/ ?>
<?php get_header(); ?>
<h1 class="heading" style="width:100%"><?php _e( 'Beliebte Zitate', 'html5blank'); ?></h1>
<?php get_sidebar(); ?>
<section id="home">
<?php get_template_part('loop'); ?>
</section>
<div id="pagination">
<?php html5wp_pagination(); ?><br>
</div>
<?php get_footer(); ?>
My loop.php looks like this:
<?php
if (have_posts()): while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(''); ?>>
LOTS OF STUFF
</article>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<?php endif; ?>
loop.php
?) The code in yourindex.php
file isn't really relevant.