【问题标题】:one page wordpress not applying templates when useing The_content一页wordpress在使用The_content时不应用模板
【发布时间】:2015-05-20 20:15:08
【问题描述】:

我正在构建一个单页 WordPress 模板。我创建了一个简单的循环,它会拉出所有页面并在同一页面上连续显示每个页面。它显示每个页面的内容,但不应用已附加到页面的模板。 这是循环...

        $args = array(
                'post_type' => 'page',
                'order' => 'ASC'
            );
            $the_query = new WP_Query( $args );         
        ?>
        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> 

    <?php the_content(); ?>
        <?php endwhile; endif; ?>

【问题讨论】:

    标签: php wordpress templates


    【解决方案1】:

    当您使用 the_content 时,该函数将只返回表中归档的 post_content 的值。所以代码按预期工作。

    试试下面的

    if ( have_posts() ){
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            locate_template( get_template_slug( $post->ID ) )
        }
    }
    

    此代码使用函数locate_template 查找模板文件,并使用get_template_slug 获取与每个页面关联的模板名称。

    如果这有帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多