Php 按标记列出同级页面

Php 按标记列出同级页面,php,wordpress,tagging,Php,Wordpress,Tagging,我试图列出父页面的所有同级(子)页面。这很容易。 但我已经标记了每个兄弟姐妹子页面,我想这样组织我的列表: Term 1 - Child/Sibling Page 1 - Child/Sibling Page 2 - Child/Sibling Page 4 Term 2 - Child/Sibling Page 3 Term 4 - Child/Sibling Page 5 - Child/Sibling Page 6 - Child/Sibling Page 7

我试图列出父页面的所有同级(子)页面。这很容易。 但我已经标记了每个兄弟姐妹子页面,我想这样组织我的列表:

Term 1
  - Child/Sibling Page 1
  - Child/Sibling Page 2
  - Child/Sibling Page 4
Term 2
  - Child/Sibling Page 3
Term 4
  - Child/Sibling Page 5
  - Child/Sibling Page 6
  - Child/Sibling Page 7
我需要这个列表同时出现在父页面和每个同级子页面上。以下是我迄今为止列出的所有兄弟页面:

<?php if($post->post_parent): ?>
<?php $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); ?>
<?php else: ?>
<?php $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'); ?>
<?php endif; ?>
<?php if ($children) { ?>
<ul class="subpage-list">
<?php echo $children; ?>
</ul>
<?php } ?>


我想我可能已经找到了答案。此代码可能有点粗糙,但据我所知,它可以根据需要工作:

<?php 
if($post->post_parent):
  $postparent = $post->post_parent;
else: 
  $postparent = $post->ID;
endif; 

$nextTagThumb='-1';
$tags = wp_get_post_tags($postparent);
foreach ($tags as $tag) :

  if ($tags) {
    $what_tag = $tags[($nextTagThumb+'1')]->term_id;
    $tag_title = $tags[($nextTagThumb+'1')]->name;
    echo '<div class="Saving_sare">'. "\n";
    echo '<h4>'.$tag_title.'</h4>'. "\n";
    echo '<ul>'. "\n";
    $args=array(
      'tag__in' => array($what_tag),
      'post__not_in' => array($postparent),
      'showposts'=>100,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile;
    }
    echo '</ul>'. "\n";
    echo '</div>'. "\n";
    wp_reset_query();
    $nextTagThumb = ($nextTagThumb+1);
  }
endforeach; 
?>


  • 我在这里有点困惑。条件
    if($post->post\u parent)后的块:查找当前帖子的所有同级,而对于顶级(无帖子父项)帖子,则查找当前帖子的子级。这是有意的吗?当你说“父页面的兄弟(子)页面”时,有点让人困惑。我知道您希望根据相关标签组织检索到的页面,但我们需要更多信息。你能概述一下页面和标签之间的关系吗?请注意,一篇文章可以有多个标签,但您似乎只想将每页放在一个标签下。问题非常好。我看看能不能更好地解释我自己。我有一个父页面,父页面和该页面有几个子页面。这些子页面都是彼此的“兄弟”。因此,如果您在父页面上,我想按标签列出所有子页面(如果页面有多个标签,它可以显示在多个标签标题下)。如果您在子页面上,我想显示同样的同级页面列表,也按标签组织。这是否澄清了任何问题?此外,我上面的代码确实正确列出了所有子/同级页面,但我不知道如何遍历标记列表。。。