admin管理员组文章数量:1414871
I've never posted here, but I'm tired of slapping code together. That said, I would be most appreciative if someone could help me with this.
I need a page template that:
- outputs the PARENT PAGEs,
- the CHILDREN PAGES of that PARENT PAGE,
- and finally output the titles and content of the GRANDCHILDREN PAGES so I can insert them into a tabbed layout.
Here's a diagram:
The idea is that visitors should be able to get to the content on the GRANDCHILDREN PAGES in two clicks.
For the PARENT PAGES, I'm using wp_nav_menu.
For the CHILD PAGES, I'm using:
<?php if ( is_page() ) { ?>
<?php
if($post->post_parent)
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul class="child-pages">
<?php echo $children; ?>
</ul>
<?php } } ?>
And to output the GRANDCHILDREN PAGES title and content, I'm using some code from the codex:
GRANDCHILDREN PAGES
<ul class="nav nav-tabs" id="myTab">
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($pages as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if($count >= 100)
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<li>
<a data-toggle="tab" href="#<?php echo $count ?>"><?php echo $page->post_title ?></a>
</li>
<?php } ?>
</ul>
GRANDCHILDREN CONTENT
<div class="tab-content">
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($pages as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if($count >= 100)
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<div class="tab-pane" id="<?php echo $count ?>">
<?php echo $content ?>
</div>
<?php } ?>
</div>
I am certain there is a more efficient way to do without a gazillion loops and queries. Anyone have any ideas? I'm want to learn, and put code an elegant solution.
本文标签: Loop that displays PARENT PAGE amp CHILD PAGE amp outputs GRANDCHILD PAGE title and content
版权声明:本文标题:Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216769a2648206.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论