show sub-subpage on wordpress homepage

2019-02-21 01:13发布

问题:

Let's say we have the following menu structure:

menu #1
menu #2
menu #3
- submenu #1
-- subsubmenu #1
-- subsubmenu #2
-- subsubmenu #3
- submenu #2
- submenu #3
menu #4
menu #5

In WordPress how can i show up on the landing/homepage (index.php hard coded) the content of the #subsubmenu #2 and #subsubmenu #3 which suppose are the last two added subsubpages under the #submenu #1 page?

I followed the suggestions by the next page:

http://codex.wordpress.org/Function_Reference/query_posts

I used the next code:

<?php query_posts('post_parent=12&posts_per_page=2'); ?>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
                <div class="entry">
                    <p><?php the_excerpt(); ?></p>
                </div>
                <?php endwhile; else : ?>
                <?php endif; ?>
                <?php wp_reset_query(); ?>

No success. Any suggestions?

回答1:

You can use the order by menu_order parameter for your query, and having a descending order to sort it out.

Note: you must use the menu_order attribute under the Page Attribute Box, at the right of the edit screen

Rewrite your query as

<?php query_posts('post_parent=12&posts_per_page=2&orderby=menu_order&order=DESC'); ?>

See: http://codex.wordpress.org/Function_Reference/query_posts#Order_.26_Orderby_Parameters



标签: php wordpress