同时向所有博客添加类别

时间:2010-10-30 作者:Innate

我正在使用WordPress mu 2.9.2,在我所有的博客上都有相同的类别结构。如何同时向所有博客添加类别?有没有一个插件可以有效地做到这一点?

1 个回复
最合适的回答,由SO网友:edelwater 整理而成

您可以为此编写一个脚本,下面是我最近用Perl编写的内容:

首先检查sql语句以检查术语是否已经存在,如果不存在,则插入它:准备好的语句:

my $wts    = $dbh->prepare(
"SELECT term_id FROM $tb_wp_terms WHERE name = ?")
or die "Couldn\'t prepare statement: " . dbh->errstr;

my $wti    = $dbh->prepare(
"INSERT INTO $tb_wp_terms
(name, slug) VALUES (?,?)")
or die "Couldn\'t prepare statement: " . dbh->errstr;
然后输入术语分类法条目:准备好的语句:

my $wtts    = $dbh->prepare(
"SELECT term_taxonomy_id FROM $tb_wp_term_taxonomy WHERE term_id = ? 
 AND taxonomy = \'".$config{\'wordpress.taxonomy_type\'}."\'")
 or die "Couldn\'t prepare statement: " . dbh->errstr;

my $wtti    = $dbh->prepare(
"INSERT INTO $tb_wp_term_taxonomy
(term_id, taxonomy, count) VALUES (?,?,1)")
or die "Couldn\'t prepare statement: " . dbh->errstr;

my $wtts_count    = $dbh->prepare(
"SELECT count FROM $tb_wp_term_taxonomy WHERE term_taxonomy_id = ? AND taxonomy =
   \'".$config{\'wordpress.taxonomy_type\'}."\'")
or die "Couldn\'t prepare statement: " . dbh->errstr;

my $wtti_count    = $dbh->prepare(
"UPDATE $tb_wp_term_taxonomy
 SET count = ?
 WHERE term_taxonomy_id = ?
 ")
or die "Couldn\'t prepare statement: " . dbh->errstr;
并使用上面的查询和一些代码(您需要检查已经有一些类别的博客)。

对于MU,只有>1的博客才能在其表名中获得博客id:

my $tb_blogid = "";
if ( $config{\'wordpress.wp_mu_blog_id\'} > 1 )
{
$tb_blogid = "_" . $config{\'wordpress.wp_mu_blog_id\'};
}
my $tb_posts                    = $config{\'wordpress.prefix\'} . $tb_blogid . "_posts";
my $tb_wp_terms                 = $config{\'wordpress.prefix\'} . $tb_blogid . "_terms";
my $tb_wp_term_taxonomy         = $config{\'wordpress.prefix\'} . $tb_blogid .     
"_term_taxonomy";
my $tb_wp_terms_relationships   = $config{\'wordpress.prefix\'} . $tb_blogid . 
"_term_relationships";
所以只要循环一下就可以了。

结束

相关推荐

WordPress删除wp_List_Categories中最后一项的分隔符

我正在尝试删除最后一个分隔符(通常是<br/> 标记,但我将其从wp\\u list\\u categories的最后一个链接更改为“/”)。基本上我想要这个:类别1//类别2//类别3//看起来像这样:类别1//类别2//类别3以下是我当前使用的代码:<?php $cat_array = array(); $args = array( \'author\' => get_the_author_meta(\'id\'),&#x