如何在WP的父页面上显示子页面的自定义字段()

我将如何显示一个父页面的子页面上的两个自定义字段。到目前为止, 这是我的代码:

< ?php $children = wp_list_pages('title_li=& child_of='.$post-> ID.'& echo=0'); if ($children) { ?> < ul> < ?php echo $children; ?> < /ul> < ?php } ?>

如何显示两个带有标题detail6和details7的自定义字段?
#1你正在寻找get_post_meta函数:
< ?php // Get the page's children $children = get_pages("child_of=" . $post-> ID); if (!empty($children)) { echo '< ul> '; foreach($children as $child) { // Get the 2 meta values from the child page $details6 = get_post_meta($child-> ID, 'details6', true); $details7 = get_post_meta($child-> ID, 'details7', true); // Display the meta values echo '< li> Details 6 = ' . $details6 . ', Details 7 = ' . $details7 . '< /li> '; } echo '< /ul> '; } ?>

#2这也可以。可能比Pat的版本更具故障。
< ?php $args = array( 'post_parent' => $post-> ID, 'post_type' => 'page', 'post_status' => 'publish'

); $ postslist = get_posts($ args); foreach($ postslist为$ post):setup_postdata($ post); ?>
< ?php the_title(); ?> < ?php the_permalink(); ?> < ?php the_permalink(); ?> < ?php echo get('details8'); ?> < ?php echo get('details9'); ?> < ?php endforeach; ?>

#3
// Get the page's children $children = get_pages('child_of=' . $post-> ID. '& depth=-2' ); if (!empty($children)) { echo '< ul class="localPlaces"> '; foreach($children as $child) { // Get the 2 meta values from the child page $details6 = get_post_meta($child-> ID, 'address 1', true); $details7 = get_post_meta($child-> ID, 'number', true); $details8 = get_the_title($child-> ID); // Display the meta values echo '< h3> '. $details8 . '< /h3> '; echo '< li> ' . $details6 . ' ' . $details7 . '< /li> '; } echo '< /ul> '; }

【如何在WP的父页面上显示子页面的自定义字段()】此方法至少还显示帖子的标题

    推荐阅读