首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过get模板部件在index.php上使用循环调用这些静态/特定页面模板?

问如何通过get模板部件在index.php上使用循环调用这些静态/特定页面模板?
EN

Stack Overflow用户
提问于 2017-04-26 06:54:10
回答 1查看 58关注 0票数 0

我在Wordpress中创建了静态页面模板,名为页面滑块。PHP,页面图像。请帮助我如何在index.php上使用循环调用这些页面,通过获取模板部件?

代码语言:javascript
复制
 <?php
$arg = array(
    'post_type' => 'pages',
);

query_posts($arg);
 while (have_posts()) : the_post();

    get_template_part( 'page-', 'the_slug()' . '.php' );

endwhile;``

?>

我试过像上面的代码一样

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-26 07:23:56

您只需要在模板调用时为每个页面添加条件。

代码语言:javascript
复制
<?php
$arg = array(
    'post_type' => 'pages',
);

 query_posts($arg);
 while (have_posts()) : the_post();
    if(is_page('slider')){
        get_template_part( 'page', 'slider' );
    }
    if(is_page('images')){
        get_template_part( 'page', 'images' );
    }

endwhile;

?>

可以在index.php文件中使用相同的格式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43627024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档