5ucms论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 13305|回复: 1
打印 上一主题 下一主题

[教程] wordPress后台文章列表显示浏览量 后台列表增加项 增加多列 增加列 增加缩略图

[复制链接]

670

主题

785

帖子

8228

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8228
跳转到指定楼层
楼主
发表于 2021-5-22 15:38:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
将下面代码放入模板函数中,如functions.php中

  1. //在后台文章列表增加一列数据
  2. add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
  3. function ashuwp_customer_posts_columns( $columns ) {
  4. $columns['views'] = '浏览';
  5. return $columns;
  6. }

  7. //输出浏览次数
  8. add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
  9. function ashuwp_customer_columns_value($column, $post_id){
  10. if($column=='views'){
  11. $count = get_post_meta($post_id, 'wl_pageviews', true);
  12. if(!$count){
  13. $count = 0;
  14. }
  15. echo $count;
  16. }
  17. return;
  18. }
复制代码


注wl_pageviews要看你的postmeta表里具体的值是不是这个 改成这个即可
想显示别的 类似用法即可
回复

使用道具 举报

670

主题

785

帖子

8228

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8228
沙发
 楼主| 发表于 2021-6-15 08:24:50 | 只看该作者
去掉不要的 增加一些别的玩意

  1. //在后台文章列表增加N列数据
  2. add_filter( 'manage_posts_columns', 'ashuwp_customer_posts_columns' );
  3.     function ashuwp_customer_posts_columns( $columns ) {
  4.         
  5.         $columns['class'] = '部位';
  6.         $columns['band'] = '品牌';
  7.         $columns['huoyuan'] = '货源';
  8.         $columns['ranks'] = '排序';
  9.         $columns['indexpic'] = '缩略图';
  10.         unset($columns['tags']); //不显示标签
  11.         unset($columns['comments']); //不显示评论
  12.         unset($columns['author']); //不显示作者
  13.         return $columns;
  14. }

  15. //输出排序、品牌等数据
  16. add_action('manage_posts_custom_column', 'ashuwp_customer_columns_value', 10, 2);
  17. function ashuwp_customer_columns_value($column, $post_id){
  18.     if($column=='ranks'){
  19.         $count = get_post_meta($post_id, 'rank', true);
  20.         if($count==''){$count = 0;}
  21.         echo $count;
  22.     }
  23.     if($column=='class'){
  24.         $terms = get_the_terms($post->ID,'class');
  25.         if($terms==''){echo '无';return;}
  26.             foreach( $terms as $term ) {
  27.                 echo $term->name;
  28.             }
  29.     }
  30.     if($column=='band'){
  31.         $terms = get_the_terms($post->ID,'band');
  32.             foreach( $terms as $term ) {
  33.                 echo $term->name;
  34.             }
  35.     }
  36.     if($column=='huoyuan'){
  37.         $terms = get_the_terms($post->ID,'huoyuan');
  38.             foreach( $terms as $term ) {
  39.                 echo $term->name;
  40.             }
  41.     }
  42.     if($column=='indexpic'){
  43.         $image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail');
  44.         echo '<img src="'.$image_url[0].'" />';
  45.     }
  46.     return;
  47. }
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|5ucms.com

GMT+8, 2024-4-20 21:30 , Processed in 0.140625 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表