After endless research with no joy I find myself having to ask for help. Below is what I would like to do:
Query the child pages from a specified parent page (id=7). For each child page, display an custom field (image) which links to the child page (its permalink)
Anybody any ideas - it sounds easy but I have not had any joy so far. Thanks in advance.
Typical! As soon as I post here I find the answer myself. Below does the above, but brings the title of each post rather than an image:
<?php query_posts(array('showposts' => 20, 'post_parent' => 7, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php } ?>
vjnoone
Member
Posted 2 years ago #
Well thanks for posting your finding. You helped me immensely!! :)
How can you do this with categories?
So that the output is a list of child categories, and the posts from each one.
for child categories:
<?php
$cats = get_categories('child_of=7&orderby=count&order=DESC');
foreach ($cats as $cat) :
$args = array(
'posts_per_page' => -1, // max number of post per child category
'cat' => $cat->term_id
);
query_posts($args);
if (have_posts()) :
echo $cat->name; //optional
while(have_posts()) :
the_post();
/*here what you want to output*/
endwhile;
endif;
endforeach;
?>
http://codex.wordpress.org/Function_Reference/get_categories