Php 将所有页面列为一个模板
我试图在WordPress中编写一个Php 将所有页面列为一个模板,php,wordpress,if-statement,Php,Wordpress,If Statement,我试图在WordPress中编写一个if语句,它说:如果有页面遵循此模板,请在此处列出所有页面(仅标题) 这是一个“服务”部分的网站上遵循的服务模板。我想这样做,因此,如果客户端在以后添加更多服务,它们将自动显示在列表中 到目前为止,我已经: <ul> <?php if ( is_page_template( 'template-services.php' ) ) : ?> <li><?php wp_title(); ?></li>
if语句,它说:如果有页面遵循此模板,请在此处列出所有页面(仅标题)
这是一个“服务”部分的网站上遵循的服务模板。我想这样做,因此,如果客户端在以后添加更多服务,它们将自动显示在列表中
到目前为止,我已经:
<ul>
<?php if ( is_page_template( 'template-services.php' ) ) : ?>
<li><?php wp_title(); ?></li>
<?php endif ?>
</ul>
您可以使用WP\u query
的meta\u query
执行此操作。模板名称存储在数据库post\u meta
表中,关键字名称为wp\u page\u template
这样的事情是可以做到的:
$arg = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'template-services.php'
)
)
);
$list_pages = new WP_Query($args);
if($list_pages -> have_posts()){
while ($list_pages->have_posts()){
$list_pages -> the_post();
the_title();
}
}