飞龙博客

feilong.org 前端开发教程

three ways display order posts meta value

飞龙修订于 20101106 12:25 32 次浏览

This post shows three ways to display and order posts by meta value num in dl dt dd h4 and p.it retrieve some values of custom fields,coding by feilong on Nov.6,2010.this post url is http://feilong.org/three-ways-display-order-posts-meta-value.

In order to use these wordpress snippets,you should use wp-postviews plugin first.

And of course,these snippets requires the functon get_attchfirst() to display the first pic of the post

//In functions.php: 
//get the first attachment picture of a post in or out of the loop feilong.org 20101105
function get_attchfirst($postid,$size = 'medium') {
$args = array(
	'order'          => 'ASC',
	'post_type'      => 'attachment',
	'post_parent'    => $postid,
	'post_mime_type' => 'image',
	'post_status'    => null,
	'numberposts'    => 1,
);$attachments = get_posts($args);if ($attachments) {
$attchfirst = wp_get_attachment_image($attachments[0]->ID, $size, false, false);
} else {
$attchfirst = '

ONE WAY:directly write template tags in your wordpress theme,this is the basic way for beginers of wordpress themes



ID,'thumbnail'); ?>

$ID, 'price', true); ?> $ID, 'new_price', true); ?>

TWO WAY: query_posts, turn the template tags above into a function in order to reuse it in wordpress themes.

'."\n";
echo '
'.get_attchfirst($post->ID,$size).'
'."\n"; echo '

'; if(function_exists('the_views')) { the_views(); } //need wp-postviews plugin the_title(); echo '

'."\n"; echo '

'.$curr.get_post_meta($post->ID, 'price', true).' '.$curr.get_post_meta($post->ID, 'new_price', true).'

'."\n"; echo ''."\n"; endwhile; else : echo 'no posts';endif; wp_reset_query(); } //Sample usage: somewhere in your wordpress theme dlh4p_list ('large','¥',1,3,'meta_value_num','DESC','views'); ?>

THREE WAY:get_posts, turn the template tags into function,just another coding.

'.get_attchfirst($post->ID,$size)."
\n"; echo '

'; if(function_exists('the_views')) { the_views(); } the_title(); echo '

'.$curr.get_post_meta($post->ID, 'price', true).' '.$curr.get_post_meta($post->ID, 'new_price', true)."

\n"; endforeach;wp_reset_query(); } //Sample usage: somewhere in your wordpress theme specialbox ('medium','%',1,3,'meta_value_num','ASC','views'); ?>

网址:https://feilong.org/three-ways-display-order-posts-meta-value
初发:20101106 12:25

想学前端?长按二维码加我微信

想学前端?点击飞龙QQ

分类: wordpress

新作:

旧文:

关闭

长按二维码 -> 识别图中二维码

打开微信,发现,扫一扫

支付完成后,点击下一步

感谢大力支持

然后你手机号:

最后点这,稍等即可