glenngeiger
Member
Posted 2 years ago #
the Codex offers this great bit of code to loop through the child pages of the parent and show the page title and page contents:
<?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;
$content = apply_filters('the_content', $content);
?>
<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
<div class="entry"><?php echo $content ?></div>
<?php
}
?>
I can't figure out how to add a 'Read More...' link to the_content, as the code above is adding the_content to the apply_filters function, and echoing out $content. Any ideas?
glenngeiger
Member
Posted 2 years ago #
Any chance this one slipped through the cracks?
charlesque
Member
Posted 2 years ago #
Hi
I have the same problem. I will be very grateful if someone can answer that.
Thanks.
charlesque
Member
Posted 2 years ago #
Ok I finally found the answer so I post here :
<?php query_posts(array( 'post_type' => 'page', 'post_parent' => '2', 'orderby' => 'menu_order', 'order' => 'ASC' )); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content('Lire la suite »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Introuvable</h2>
<p class="center">Désolé, mais vous cherchez quelque chose qui ne se trouve pas ici.</p>
<?php get_search_form(); ?>
<?php endif; ?>
josef.lagunas
Member
Posted 1 year ago #
looks like you forgot one thing. the global $more.
<? global $more; ?>
<? $more = 0; ?>
Thanks both of you man!
This is my final code after your help:
<?php
$i = 0;
$count = 3;
global $more;
$more = 0;
$parent_page_id = 1092;
query_posts(array( 'post_type' => 'page', 'post_parent' => $parent_page_id, 'orderby' => 'menu_order', 'order' => 'DESC' ));
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="grid_4 <?php if($i % $count == 0) echo 'alpha';else if(($i+1) % $count == 0) echo 'omega';?>">
<?php
if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())){ ?>
<div class="post-img">
<a title="<?php get_the_title(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" ><?php the_post_thumbnail('service-img');?></a>
</div>
<?php } ?>
<h3 class="post-title"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content('Read more →'); ?></div>
</div>
<?php
$i++;
endwhile;
endif;
?>
deathski
Member
Posted 1 year ago #
Is the code above limited to display the subpages/children of the indicated parent_page_id (1092)?
I wish to display all my current Parent pages.
This code just displays subpages deathski
deathski
Member
Posted 1 year ago #
I see. How can I modify this query to get all the parent pages instead of posts? Newbie here.
query_posts($query_string . "&showposts=$post_number&paged=$paged&cat=$cat");
query_posts($query_string . "&post_parent=0&showposts=$post_number&paged=$paged&cat=$cat");
deathski
Member
Posted 1 year ago #
Thanks but it still returns my posts and not pages.
did you try to add 'post_type' => 'page' ?
query_posts($query_string . "&post_parent=0&post_type=page&showposts=$post_number&paged=$paged&cat=$cat");
or
query_posts(array( 'post_type' => 'page', 'post_parent' => 0, 'orderby' => 'menu_order', 'order' => 'DESC' ));
deathski
Member
Posted 1 year ago #
Thanks man. post_type did it. Thank you
Please mark thread as resolved so that
- others with similar problem can see it as resolved and will read this thread for help if they have similar problem
- people providing help see it as resolved and will not waste time reading this post.