问题描述如下:
在Wordpress中,如何给已经发布过的文章,批量添加TAG?
例子:我发布了10篇文章,没有为这些文章添加TAG。现在,我想批量为这些文章同时添加:北京,北漂,失业。这三个TAG。
然后,当用户访问到mydomain.com/tag/北京这样的url时,页面会把内容中包含”北京”关键词的文章列表出来。
这是一位道友在百度知道里的提问,百度了一下,wordpress管理分类、标签之类的插件很多;但针对这样的小要求,完全可以自己手动来轻易地解决;代码如下:
可以在当前皮肤的functions.php里自建一个函数;
function naruco_mod_tags(){ $post_ids = array(1,2,3,4,5,6,7,8,9,10); foreach( $post_ids as $k => $post_id ){ wp_set_post_tags( $post_id, array('tag1','tag2','tag3') ); } }
手动输入你的日志ID串;如果你是批量修改,那么你需要从库里读取出ID串;
然后附加到HOOKS上,执行一次再行删除这个函数就可以了;
如:
add_action('edit_post','naruco_mod_tags'); //后台更新一次任意一篇日志就可以实现效果。
很简单吧?呵呵~执行完后,记得删除这个或注释到add_action这一句就OK了,避免重复执行!
(同步投稿:wpcourse.com)
This is a good tip especially to those new to the blogosphere.
Short but very accurate information… Thank
you for sharing this one. A must read post!
An outstanding share! I’ve just forwarded this onto a friend who was conducting a little homework on this. And he actually bought me lunch simply because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanks for spending some time to talk about this topic here on your web page.