How to display child page from specific parent page in homepage?
-
How to display child page from specific parent page in homepage ? This is my page structure Home About Us Hotel Category Hotel A Room 1 Room 2 Hotel B Room 1 Room 2 Hotel C Room 1 Room 2 Contact Us And i try to achieve this at homepage(parent page is Hotel Category : id=8) Hotel A Hotel B Hotel C List Hotel A, Hotel B and Hotel C with some except and thumbnail image(this magic field)
-
Answer:
Try this http://wordpress.org/extend/plugins/query-posts/. You can use it in your sidebar(as widget) and set which posts you want to show.
ruslyrossi at WordPress Visit the source
Other answers
Below code (Template for show child pages with title and excerpt) might useful to you. if you are using wordpress category->post instead of worpdress page, change the wp_query accordingly. You can get more information about wp_query : http://codex.wordpress.org/Class_Reference/WP_Query Here's the template code: <?php /** Template Name: show child pages */ get_header(); ?> <div id="container"> <div id="content" role="main"> <?php get_template_part( 'loop', 'page' ); global $post; $args=array( "post_parent" => $post->ID, 'paged' => get_query_var( 'page' ), 'post_type' => 'page' ); // The Query $the_query = new WP_Query( $args ); // The Loop echo "<ul>"; while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<li class="chiled-title">'; the_title(); the_excerpt(); echo '</li>'; endwhile; echo "<ul/>"; ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <div id="nav-below" class="navigation"> <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div> </div><!-- #nav-below --> <?php endif; ?> <?php // Reset Post Data wp_reset_postdata(); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Fazle Elahee
This should do it. <?php $pages = get_pages('child_of=199'); foreach($pages as $child) { ?> <h3><?php echo get_the_title($child->ID); ?></h3> <?php // This next line gets the full page of content // echo get_post_field('post_content', $child->ID); // This next line will cut the content off at 450 letters // With a read more link under it echo '<p>' . substr(get_post_field('post_content', $child->ID), 0, 450) . '</p>'; ?> <a href="<?php echo get_permalink( $child->ID ); ?>"> READ MORE </a> <?php } ?> Change "child_of=199" with the ID of the page you want to get the children of. There is a line that is commented out, that line will get the full page of content The line that is being used to get content will only get the first 450 letters. There has to be a better way to get content, as this pulls in the HTML and all - so if that first 450 letter happens to land in the middle of a image you will have broken text. I am sure a quick google search of "get post content by Id" should help with that part
Chaos67731
Related Q & A:
- how to perform certain code on specific time in android?Best solution by Yahoo! Answers
- How do I update only a specific svn external on first update?Best solution by stackoverflow.com
- How to build child modules independently from parent in Maven?Best solution by stackoverflow.com
- How can I block a specific web page?Best solution by Yahoo! Answers
- How can a child make money?Best solution by wikihow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.