本站点用的是懿古今的NANA主题,当写完一篇文章时,并在文章底部勾选“推送到[站长推荐]小工具”后,文章发布后,会在前端侧边栏显示站长推荐的文章。可经过很长时间之后,推荐的文章数多了,这时,要想在后台文章列表里,查看哪些是推荐的哪些不是推荐的,就只能一篇一篇的进入编辑模式下去看,不太直观,且麻烦。/p>
今天,我就介绍下如何在WordPress后台的文章列表增加栏目(站长推荐)。效果图如下:
要实现上面的效果,也很简单,只需要在当前主题的functions的?>添加下列代码即可。
//1~ 在后台文章列表增加1列数据,展示站长推荐 add_filter( 'manage_posts_columns', 'yiy_customer_posts_columns' ); function yiy_customer_posts_columns( $columns ) { $columns['hots'] = '站长推荐'; return $columns; } //2~ 输出结果 add_action('manage_posts_custom_column', 'yiy_customer_columns_value', 10, 2); function yiy_customer_columns_value($column, $post_id){ if($column=='hots'){ $hot_value = get_post_meta($post_id,'hot',true); if($hot_value==true) {echo Yes; //站长推荐显示Yes }else echo No; //不是显示No } return; }
好了,到此就结束了,是不是很简单呢。
发表于2年前 (2019-02-24)
非常有用的技巧,省得一个一个去找 [赞]
发表于2年前 (2019-02-24)
@Fatansy 对你有所帮助,我很高兴。希望常来看看。