在Wordpress中打开父页/子页时显示子页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Wordpress中打开父页/子页时显示子页相关的知识,希望对你有一定的参考价值。
function navigation() { global $wpdb, $post; $query = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'page' AND post_parent = 0"); echo '<div id="nav">'; echo '<ul>'; foreach ($query as $obj) { echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$obj->ID.'">'.$obj->post_title.'</a></li>'; $sub_query = $wpdb->get_results("SELECT ID, post_title, post_parent FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'page' AND post_parent = {$obj->ID}"); foreach($sub_query as $sub_obj) { if($post->ID == $sub_obj->post_parent) echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$sub_obj->ID.'" class="subpage">'.$sub_obj->post_title.'</a></li>'; if($post->post_parent == $sub_obj->post_parent) echo '<li><a href="'.get_bloginfo('wpurl').'/?page_id='.$sub_obj->ID.'" class="subpage">'.$sub_obj->post_title.'</a></li>'; } } echo '</ul>'; echo '</div>'; }
以上是关于在Wordpress中打开父页/子页时显示子页的主要内容,如果未能解决你的问题,请参考以下文章