Alrighty, I figured it out 🙂
<?
$pages = $wpdb->get_results("
SELECT * from $wpdb->posts
WHERE post_type='page'
AND post_parent=$post->ID
ORDER BY post_title
");
//the above checks the database for posts that are actually pages, it then (I think?) put these into the pages variable, and orders
//them by title.
foreach($pages as $page) : // christ, I don't know php... so I guess this makes teh variable of page act as pages but singularly?
$profile_image = get_post_meta($page->ID, 'profile_image', $single = true); // this bit is to pull any meta from the child page
//in this case it's the custom field with the profile_image key, turning to to the variable profile image
endforeach;
foreach($pages as $page) :
//echo '<h2><a href="' . get_permalink($page->ID) . '" title="' . $page->post_title . '">' . $page->post_title . '</a></h2>'; //this would, if uncommented, show the page title.
echo '<p><a href="' . get_permalink($page->ID) . '" title="' . $page->post_title . '"><img src="/wp-content/plugins/fresh-page/files_flutter/' . $profile_image . '" /></a></p>';
// using flutter, so I've pulled the profile image from the page, linked it to the folder that it resides in and linked around it to the actual child page.
endforeach;
?>
The code has been pinched from various places, I’m only a beginner in php so I’m quite proud of figuring this out!
hum ok so the images don’t work… it’s just pulling the same meta in from the first page
fixed it! Works like a charm now :
<?
$pages = $wpdb->get_results("
SELECT * from $wpdb->posts
WHERE post_type='page'
AND post_parent=$post->ID
ORDER BY post_title
");
//the above checks the database for posts that are actually pages, it then (I think?) put these into the pages variable, and orders
//them by title.
foreach($pages as $page) :
$profile_image = get_post_meta($page->ID, 'profile_image', $single = true);
// this bit is to pull any meta from the child page
//in this case it's the custom field with the profile_image key, turning to to the variable profile_image
//echo '<h2><a href="' . get_permalink($page->ID) . '" title="' . $page->post_title . '">' . $page->post_title . '</a></h2>'; //this would, if uncommented, show the page title.
echo '<p><a href="' . get_permalink($page->ID) . '" title="' . $page->post_title . '"><img src="/wp-content/plugins/fresh-page/files_flutter/' . $profile_image . '" /></a></p>';
// using flutter, so I've pulled the profile image from the page, linked it to the folder that it resides in and linked around it to the actual child page.
endforeach;
?>
is there an easier way to do this query posts?
I like to do it like this, using setup_postdata for easy access to post stuff like the_title. Just cobbled together too, but still:
<?php
$current_page = $post->ID;
$querystr = "
SELECT * from $wpdb->posts
WHERE post_type = 'page'
AND post_parent = $current_page
";
$child_pages = $wpdb->get_results($querystr, OBJECT);
if ($child_pages):
foreach($child_pages as $post) :
setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>
<?php else : ?>
// Do stuff when no child page available
<?php endif; ?>
<?php rewind_posts(); ?>
I’ve added rewind_posts so this stuff doesn’t mess up my original query when on an archive page and such.
cool, I’m not sure if I need rewind posts? but I’m not sure… maybe i should put it in a one f the temp query things though? Would it affect searchs and the like?
I had some troubles with an additional query and the ‘edit post’ link, where Kafkaesqui pointed me to rewind_posts.
Not sure what you mean by affecting search though.
I found this posting by mistake and it solved a problem I was having.
Thanks
http://wordpress.org/support/topic/246014