0

我会在侧栏中使用wp_list_pages和afc。wp_list_pages with afc(高级自定义字段)

列表页面的正常输出是这样的

<ul> 
<li>page 1</<li> 
<li>page 2</<li> 
<ul> 
<li>page 2.1</<li> 
<li>page 2.2</<li> 
<li>page 2.3</<li> 
</ul> 
<li>page 3</<li> 
<li>page 4</<li> 
<li>page 5</<li> 
<li>page 6</<li> 
</ul> 

些页面自定义字段,我想这样的事情

<ul> 
<li>page 1</<li> 
<li>page 2 <span> - **custom field info**</span></<li> 
<ul> 
<li>page 2.1</<li> 
<li>page 2.2<span> - custom field info</span></<li> 
<li>page 2.3</<li> 
</ul> 
<li>page 3</<li> 
<li>page 4<span> - custom field info</span></<li> 
<li>page 5</<li> 
<li>page 6</<li> 
</ul> 

与我想这经常WordPress的自定义字段:

wp_list_pages("title_li=".$post->ID."&meta_key=key"); 

但这只是过滤器和只显示我的网页与关键而不是额外的。 我该如何解决这个小问题?任何(其他)想法?

谢谢

回答

1

你需要做的是这样的:

$args = array(
    'post_type' => 'page', 
); 
// The Query 
$query = new WP_Query($args); 

// The Loop 
if ($query->have_posts()) { 

    echo '<ul>'; 

    while ($query->have_posts()) { 

     $query->the_post(); 

     if (get_field("field_name")) { 
      $custom_field_value = ' <span>' . get_field("field_name") . '</span>'; 
     } else { 
      $custom_field_value = ''; 
     } 

     echo '<li>' . get_the_title() . $custom_field_value . '</li>'; 
    } 

    echo '</ul>'; 

} else { 
    // no posts found 
} 

/* Restore original Post Data */ 
wp_reset_postdata(); 
相关问题