admin管理员组文章数量:1024026
I'm trying to do something similar to the question in Exclude pages with certain template from wp_list_pages, but the $exclude
variable doesn't seem to be returning the _wp_page_template
value to then filter out the relevant pages with the template guidance-note-template.php
from the list. Any tips, greatly appreciated.
<?php
global $post;
$exclude = [];
foreach(get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'guidance-note-template.php']) as $page) {
$exclude[] = $page->post_id;
}
$children = get_pages( array( 'child_of' => $post->ID ) );
$hasChild = (count( $children ) > 0 );
$page_id = ($hasChild) ? $post->ID : wp_get_post_parent_id( $post->ID );
wp_list_pages( array(
'title_li' => '',
'child_of' => $page_id,
'exclude' => implode(",", $exclude),
));
?>
I'm trying to do something similar to the question in Exclude pages with certain template from wp_list_pages, but the $exclude
variable doesn't seem to be returning the _wp_page_template
value to then filter out the relevant pages with the template guidance-note-template.php
from the list. Any tips, greatly appreciated.
<?php
global $post;
$exclude = [];
foreach(get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'guidance-note-template.php']) as $page) {
$exclude[] = $page->post_id;
}
$children = get_pages( array( 'child_of' => $post->ID ) );
$hasChild = (count( $children ) > 0 );
$page_id = ($hasChild) ? $post->ID : wp_get_post_parent_id( $post->ID );
wp_list_pages( array(
'title_li' => '',
'child_of' => $page_id,
'exclude' => implode(",", $exclude),
));
?>
Share
Improve this question
asked Apr 26, 2019 at 11:44
SketchybearSketchybear
233 bronze badges
1 Answer
Reset to default 0For children pages to show, the 'hierarchical' => 0
option must also be set in your get_pages() function.
I copied your code and initially had the same results (it returned no pages). Adding in the hierarchical setting set to 0 made it return the 2 pages I had set to that template, which could then be excluded. It then output all the other children except for those 2, as I think you wanted.
Credit for solution: Older Stack Overflow answer
I'm trying to do something similar to the question in Exclude pages with certain template from wp_list_pages, but the $exclude
variable doesn't seem to be returning the _wp_page_template
value to then filter out the relevant pages with the template guidance-note-template.php
from the list. Any tips, greatly appreciated.
<?php
global $post;
$exclude = [];
foreach(get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'guidance-note-template.php']) as $page) {
$exclude[] = $page->post_id;
}
$children = get_pages( array( 'child_of' => $post->ID ) );
$hasChild = (count( $children ) > 0 );
$page_id = ($hasChild) ? $post->ID : wp_get_post_parent_id( $post->ID );
wp_list_pages( array(
'title_li' => '',
'child_of' => $page_id,
'exclude' => implode(",", $exclude),
));
?>
I'm trying to do something similar to the question in Exclude pages with certain template from wp_list_pages, but the $exclude
variable doesn't seem to be returning the _wp_page_template
value to then filter out the relevant pages with the template guidance-note-template.php
from the list. Any tips, greatly appreciated.
<?php
global $post;
$exclude = [];
foreach(get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'guidance-note-template.php']) as $page) {
$exclude[] = $page->post_id;
}
$children = get_pages( array( 'child_of' => $post->ID ) );
$hasChild = (count( $children ) > 0 );
$page_id = ($hasChild) ? $post->ID : wp_get_post_parent_id( $post->ID );
wp_list_pages( array(
'title_li' => '',
'child_of' => $page_id,
'exclude' => implode(",", $exclude),
));
?>
Share
Improve this question
asked Apr 26, 2019 at 11:44
SketchybearSketchybear
233 bronze badges
1 Answer
Reset to default 0For children pages to show, the 'hierarchical' => 0
option must also be set in your get_pages() function.
I copied your code and initially had the same results (it returned no pages). Adding in the hierarchical setting set to 0 made it return the 2 pages I had set to that template, which could then be excluded. It then output all the other children except for those 2, as I think you wanted.
Credit for solution: Older Stack Overflow answer
本文标签: wp list pagesExclude certain template from wplistpages
版权声明:本文标题:wp list pages - Exclude certain template from wp_list_pages 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745548020a2155486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论