以下是最终工作代码,以供将来参考
function mam_listing($args) {
$args = array(
\'posts_per_page\' => -1,
\'cat\' => 6,
\'meta_key\' => \'Points\',
\'orderby\' => \'meta_value_num\'
);
$outputt = \'<table width="100%" cellpadding="2" border="0">\';
$no=0;
$points_query = new WP_Query( $args );
while( $points_query->have_posts() ):
$points_query->the_post();
$no = $no+1;
$outputt .= \'<tr>\';
$outputt .= \'<td>\';
$outputt .= \'Position \'.$no;
$outputt .= \'</td>\';
$outputt .= \'<td>\';
$outputt .= \'<a href="\' . get_permalink($post->ID) . \'">\' . get_the_title($post->ID) .\'</a>\';
$outputt .= \'</td>\';
$outputt .= \'<td>\';
$temp = get_post_custom_values("Points");
$outputt .= $temp[0];
$outputt .= " Points";
$outputt .= \'</td></tr>\';
endwhile;
$outputt .= \'</table>\';
return $outputt;
}
add_shortcode( \'mam-listing\', \'mam_listing\' );