the_content of template page

时间:2014-05-14 作者:dborghez

使用页面模板中的\\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;条目内容页;但是它是空的,我只需要显示内容<奇怪的是,如果我点击;“查看页面”;在管理面板中,预览显示了内容,但我的网站中没有<有什么想法吗<谢谢!

编辑:页面通过;查看页面:via view-page主页中的页面:enter image description here

编辑2:我试着去;“读取设置”;如果我像首页一样设置页面(模板登陆),我可以看到内容

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;
        ?>  

SO网友:Andrew Lazarus

你试过使用整个循环吗?

<?php $loop = new WP_Query();
if ( $loop->have_posts() ) : 
    while ( $loop->have_posts() ) : 
    $loop->the_post(); ?>
    <!-- before -->
        <?php the_content(); ?>
    <!-- after -->
    <?php endwhile; else: ?>
    <p><?php _e( \'Nope. Doesn\\\'t exist\' ); ?></p>
<?php endif; ?>

结束

相关推荐

wp_dropdown_pages auto submit

我下面的内容目前运行良好,但有一个问题除外:当选择一个选择项时,它将正确转到子页面-但是,如果已经在主站点的子页面上,并且从下拉列表中选择了一个项,则选择url将附加到现有页面url,而不是作为完整url传递。例如如果在现场。com并选择选项1,我们将导航到站点。com/choice1/-如果我们在现场。com/choice1和choice2被选中,它试图将我们引导到站点。com/choice1/choice2-我不知道如何调整下面的代码来传递完整的URL。任何帮助都将不胜感激。<?php