使用页面模板中的\\u内容时,不会显示任何内容。
循环调用索引中的页面模板:
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();
但它不起作用,我只能看到这个类的div;条目内容页;但是它是空的,我只需要显示内容<奇怪的是,如果我点击;“查看页面”;在管理面板中,预览显示了内容,但我的网站中没有<有什么想法吗<谢谢!
编辑:页面通过;查看页面:主页中的页面:
编辑2:我试着去;“读取设置”;如果我像首页一样设置页面(模板登陆),我可以看到内容
最合适的回答,由SO网友:dborghez 整理而成
通过以下方式解决:(index.php)
<?php
$args = array(
\'child_of\' => 0,
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\',
\'hierarchical\' => 1,
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
\'post_parent\' => \'0\',
\'posts_per_page\' => \'100\'
);
$wp_query = query_posts($args);
query_posts($args); // Query all published pages without parents
$first_loop = true;
if (have_posts()) :
while (have_posts()) : the_post();
//Determine template for page style
$template = get_post_meta( get_the_ID(), \'_wp_page_template\', true );
$parent_id = get_the_ID();
switch($template) {
case \'template-portfolio.php\':
get_template_part( \'includes/portfolio\' );
break;
case \'template-landing.php\':
echo get_template_part( \'includes/landing\' );
break;
}
endwhile;
endif;
?>