5ucms论坛
标题:
wordPress后台文章列表显示浏览量 后台列表增加项 增加多列 增加列 增加缩略图
[打印本页]
作者:
admin
时间:
2021-5-22 15:38
标题:
wordPress后台文章列表显示浏览量 后台列表增加项 增加多列 增加列 增加缩略图
将下面代码放入模板函数中,如functions.php中
//在后台文章列表增加一列数据
add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
function ashuwp_customer_posts_columns( $columns ) {
$columns['views'] = '浏览';
return $columns;
}
//输出浏览次数
add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
function ashuwp_customer_columns_value($column, $post_id){
if($column=='views'){
$count = get_post_meta($post_id, 'wl_pageviews', true);
if(!$count){
$count = 0;
}
echo $count;
}
return;
}
复制代码
注wl_pageviews要看你的postmeta表里具体的值是不是这个 改成这个即可
想显示别的 类似用法即可
作者:
admin
时间:
2021-6-15 08:24
去掉不要的 增加一些别的玩意
//在后台文章列表增加N列数据
add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
function ashuwp_customer_posts_columns( $columns ) {
$columns['class'] = '部位';
$columns['band'] = '品牌';
$columns['huoyuan'] = '货源';
$columns['ranks'] = '排序';
$columns['indexpic'] = '缩略图';
unset($columns['tags']); //不显示标签
unset($columns['comments']); //不显示评论
unset($columns['author']); //不显示作者
return $columns;
}
//输出排序、品牌等数据
add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
function ashuwp_customer_columns_value($column, $post_id){
if($column=='ranks'){
$count = get_post_meta($post_id, 'rank', true);
if($count==''){$count = 0;}
echo $count;
}
if($column=='class'){
$terms = get_the_terms($post->ID,'class');
if($terms==''){echo '无';return;}
foreach( $terms as $term ) {
echo $term->name;
}
}
if($column=='band'){
$terms = get_the_terms($post->ID,'band');
foreach( $terms as $term ) {
echo $term->name;
}
}
if($column=='huoyuan'){
$terms = get_the_terms($post->ID,'huoyuan');
foreach( $terms as $term ) {
echo $term->name;
}
}
if($column=='indexpic'){
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail');
echo '<img src="'.$image_url[0].'" />';
}
return;
}
复制代码
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2