When I use the_content in the page-template doesn't show anything.
Loop to call the page-template in the index:
index.php
<?php
/**
* Main template file
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Eleven
*/
get_header();
$pages = get_pages();
foreach ($pages as $page_data) {
$title = $page_data->post_title;
$template = get_post_meta( $page_data->ID, '_wp_page_template', true );
switch($template) {
case 'template-portfolio.php':
get_template_part( 'includes/portfolio' );
break;
case 'template-landing.php':
echo get_template_part( 'includes/landing' );
break;
}
}
get_footer();
landing.php
:
<div id="opening" style="width:100%; height:100vh; background: white; background-size:cover; margin: 0 0 -86px 0; ">
<div id="text_opening">
<!--<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
Stai visitando la pagina <?php echo $paged; ?>-->
<?php while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
</div>
</div>
template-landing.php
:
<?php
/*
Template Name: Landing
*/
get_header();
echo get_template_part( 'includes/landing' );
get_footer();
But it doesn't work, i can see only the div with the class "entry-content-page" but it's empty
I need to display only the content.
The strange thing is that if I click on "view page" in the admin panel, the preview show the content but in my site isn't there.
Any ideas?
Thanks!
EDIT:
PAGE VIA "VIEWPAGE":
PAGE IN THE HOME:
EDIT2:
I tried to go to the "reading setting" and if I set that page (template-landing) like front page I can see the content
wp_reset_query
, why is that there? It suggests you've usedquery_posts
somewhere ( never usequery_posts
, seriously ). Can you expand your code example to include relevant parts such as any querys you make prior to the code? Can you also wrap your code in an if( have_posts() ) and print something out in the else case? You're looping over posts but you're not checking if you have any posts to begin with