5ucms论坛

标题: wordPress后台文章列表显示浏览量 后台列表增加项 增加多列 增加列 增加缩略图 [打印本页]

作者: admin    时间: 2021-5-22 15:38
标题: wordPress后台文章列表显示浏览量 后台列表增加项 增加多列 增加列 增加缩略图
将下面代码放入模板函数中,如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表里具体的值是不是这个 改成这个即可
想显示别的 类似用法即可
作者: admin    时间: 2021-6-15 08:24
去掉不要的 增加一些别的玩意

  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. }
复制代码





欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2