Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何通过使用循环获取模板部分在index.php上集体调用这些静态/特定页面模板?_Wordpress - Fatal编程技术网

Wordpress 如何通过使用循环获取模板部分在index.php上集体调用这些静态/特定页面模板?

Wordpress 如何通过使用循环获取模板部分在index.php上集体调用这些静态/特定页面模板?,wordpress,Wordpress,我在Wordpress中创建了静态页面模板,命名为页面滑块。PHP,页面图像。PHP等。请帮助我如何通过使用循环获取模板部分在index.PHP上集体调用这些页面 <?php $arg = array( 'post_type' => 'pages', ); query_posts($arg); while (have_posts()) : the_post(); get_template_part( 'page-', 'the_slug()' . '.php'

我在Wordpress中创建了静态页面模板,命名为页面滑块。PHP,页面图像。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;``

?>


我已经尝试了上面的代码

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

<?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文件中使用相同的格式

您可以检查调用哪个文件吗?index.php或page.php?如果page.php正在调用页面,那么您需要在该文件中添加逻辑,而不使用while循环和wp_查询:如以下If(is_page('slider')){get_template_part('page','slider');}If(is_page('images')){get_template_part('page','images');}先生,我在page.php上尝试了一下,但仍然不起作用。我再次告诉您我想做什么。我已经从一页html模板的不同部分创建了静态页面模板,现在我想在index.php或page.php上调用这些模板(page slider.php,page image.php),除非对每个文件再次使用get_template_part函数,例如,我想要像这样的好心先生,帮帮我