Wordpress显示子页面数据:标题,特色图像和自定义字段

问题描述:

我正在显示当前页面的子页面。随着特色图片,标题拉动。我也想通过我添加的自定义字段。我输出这个在html,所以它看起来像每个子页面都有自己的盒子,与特色的图像填充框,图像顶部标题和自定义字段值坐在标题下。Wordpress显示子页面数据:标题,特色图像和自定义字段

但我不能让自定义字段正确显示,我只是得到值1,不知道如果我已经正确地转换数组?

你能帮我走出来输出自定义字段 'PageTag'

https://i.stack.imgur.com/vzCBU.png https://i.stack.imgur.com/BwfuV.png

WordPress的模板代码

<div class="childPages"> 
    <?php 
    $subs = new WP_Query( 
    array( 
     'post_parent' => $post->ID, 
     'post_type' => 'page', 
     'meta_key' => '_thumbnail_id' 
    ) 
); 
if($subs->have_posts()) : 
    while($subs->have_posts()) : 
    $subs->the_post(); 
    $pageTag = get_post_meta($post->ID, '_PageTag' , true); 
    echo '<div class="childPageBlock"> <a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail().'<div class="childPageBlockText"><h3>'.get_the_title().'</h3><span>'.print_r($pageTag).'</span></div></a></div>'; 
    endwhile; 
endif; 
wp_reset_postdata(); ?> 
</div> 
+0

它是'PageTag'还是'_PageTag'?你在你的问题中提到一个,然后在你的代码中查询另一个。 – yivi

+0

这是PageTag。当我在网上寻找有人指出要在标签前放置一个_的答案时。 – stuartfmc

+0

我在问题描述中添加了两个图像链接。 – stuartfmc

卸下的print_r(),并留下其作为

'。$ pageTag'。

工作!