我在Wordpress中创建了静态页面模板,名为页面滑块。PHP,页面图像。请帮助我如何在index.php上使用循环调用这些页面,通过获取模板部件?
<?php
$arg = array(
'post_type' => 'pages',
);
query_posts($arg);
while (have_posts()) : the_post();
get_template_part( 'page-', 'the_slug()' . '.php' );
endwhile;``
?>我试过像上面的代码一样
发布于 2017-04-26 07:23:56
您只需要在模板调用时为每个页面添加条件。
<?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文件中使用相同的格式。
https://stackoverflow.com/questions/43627024
复制相似问题