2013-02-20 37 views
1

我正在嘗試製作父頁的所有同級(子)頁的列表。這很簡單。 但我標記每個兄弟子頁面,我想舉辦像這樣我的列表:按標籤列出的同級頁

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 } ?> 
+1

我在這裏有點困惑。條件爲'if($ post-> post_parent):...'後的塊會查找當前帖子的所有同級,而對於最高級別(無post_parent)帖子,則查找當前帖子的子級。這是打算?當你說**父母頁面的「兄弟(子)頁面」時,這有點令人困惑。我看到你想根據其關聯的標籤來組織檢索到的頁面,但我們需要更多信息。你能概述頁面和標籤是如何相關的嗎?請注意,帖子可以有多個標籤,但您似乎只想將每個頁面放在一個標籤下。 – kjetilh 2013-02-20 10:26:23

+0

優秀的問題。我會看看我能否更好地解釋自己。 我有一個父頁面,父母 ,該頁面有幾個子頁面。這些孩子頁面都是彼此的「兄弟姐妹」。 所以,如果你在父頁面上,我想按標籤列出所有的孩子(如果頁面有多個標籤,它可以顯示在多個標籤標題下)。而且,如果你在一個子頁面上,我想顯示同樣的兄弟頁面列表,也是按標籤組織的。這是澄清任何? 此外,我上面的代碼沒有正確列出所有的孩子/兄弟姐妹頁,但我無法弄清楚如何遍歷標籤列表... – f8xmulder 2013-02-20 16:20:28

回答

0

我相信我可能想出了一個答案。此代碼可能有點粗糙,但據我所知可以根據需要運行:

<?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; 
?>