在使用wp\\U list\\U页面时,我试图为每个页面引入一个自定义字段vales。例如,我想在侧边栏中列出每个公文包项目,但也要通过拉入自定义字段值来显示其工作类型的原因,使其看起来像这样:
公文包项目1类型:Web设计公文包项目2类型:Web开发这是我用来拉入自定义帖子类型的代码,它工作得很好,我只是不知道如何让它也拉入自定义字段值:
function wp_list_post_types( $args ) {
$defaults = array(
\'numberposts\' => -1,
\'offset\' => 0,
\'orderby\' => \'menu_order, post_title\',
\'post_type\' => \'our-work\',
\'depth\' => 0,
\'show_date\' => \'\',
\'date_format\' => get_option(\'date_format\'),
\'child_of\' => 0,
\'exclude\' => \'\',
\'include\' => \'\',
\'title_li\' => __(\'\'),
\'echo\' => 1,
\'link_before\' => \'\',
\'link_after\' => \'\',
\'exclude_tree\' => \'\' );
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$output = \'\';
$current_page = 0;
// sanitize, mostly to keep spaces out
$r[\'exclude\'] = preg_replace(\'/[^0-9,]/\', \'\', $r[\'exclude\']);
// Allow plugins to filter an array of excluded pages (but don\'t put a nullstring into the array)
$exclude_array = ( $r[\'exclude\'] ) ? explode(\',\', $r[\'exclude\']) : array();
$r[\'exclude\'] = implode( \',\', apply_filters(\'wp_list_post_types_excludes\', $exclude_array) );
// Query pages.
$r[\'hierarchical\'] = 0;
$pages = get_posts($r);
if ( !empty($pages) ) {
if ( $r[\'title_li\'] )
$output .= \'<li class="pagenav">\' . $r[\'title_li\'] . \'<ul>\';
global $wp_query;
if ( ($r[\'post_type\'] == get_query_var(\'post_type\')) || is_attachment() )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r[\'depth\'], $current_page, $r);
if ( $r[\'title_li\'] )
$output .= \'</ul></li>\';
}
$output = apply_filters(\'wp_list_pages\', $output, $r);
if ( $r[\'echo\'] )
echo $output;
else
return $output;
}