2
상위 페이지 수준에서 하위 페이지 목록을 유지하면서 계층 내에서 더 멀리 탐색하기 위해 내 테마 functions.php
에 함수를 만들었습니다.
내 문제는 내가 page.php
테마 파일 내에서 함수를 호출 할 때 나는 아무것도 얻지 못한다는 것입니다.함수가 "functions.php"에서 값을 반환하지 않습니다.
functions.php :
function get_top_parent_children($the_id,$start = 0,$walk = null){
$current_post = get_post($the_id);
$walk[] = $current_post;
if($current_post->post_parent){
get_top_parent_children($current_post->post_parent,$start,$walk);
} else {
$output = array_reverse($walk);
return get_children($output[$start]->ID);
}
}
page.php :
<?php get_header(); ?>
<div id="primary" class="clearfix">
<div id="content">
<?php the_post(); ?>
<?php $children = get_top_parent_children($id,1); ?>
<?php if ($children) { ?>
<section id="post-topic">
<h2><?php the_title() ?> Topics</h2>
<ul class="clearfix">
<?php foreach($children as $child){ ?>
<li>
<a href="<?php echo get_permalink($child->ID) ?>"> <?php echo child->post_title ?> </a>
</li>
<?php }; ?>
</ul>
</section>
<?php }; ?>
<?php get_template_part('content', 'page'); ?>
</div>
<aside>
<?php dynamic_sidebar('Page Sidebar'); ?>
</aside>
</div>
<?php get_footer(); ?>
get_children을 묶어야합니다. – ajreal