我使用Wordpress多站点在一个WP安装中容纳了多个站点
我希望导航显示每个网站都有指向该网站的链接。
我正在使用此功能执行此操作
<?php
$bcount = get_blog_count();
global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
if(!empty($blogs)){
?>
<ul class="nav navbar-nav">
<li class="portalHome"><a href="dashboard.html">
<i class="fa fa-home"></i>
<i class="fa fa-chevron-right pull-right chervonMobNav"></i></a></li>
<?php
foreach($blogs as $blog){
$details = get_blog_details($blog->blog_id);
if($details != false){
$addr = $details->siteurl;
$name = $details->blogname;
if(!(($blog->blog_id == 1)&&($show_main != 1))){
?>
<li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
<a href="<?php echo $addr; ?>"><?php echo $name;?> <i class="fa fa-chevron-right pull-right chervonMobNav"></i></a>
</li>
<?php
}
}
}
?></ul><?php
}
?>
它有效,但我也收到了错误
Warning: Missing argument 2 for wpdb::prepare()
对于wpdb :: prepare()
,第二个参数应该是什么?答案 0 :(得分:2)
$ wpdb-&gt; prepare在php中作为sprintf工作
来自php.net的例子
$ num = 5; $ location =&#39; tree&#39;;
$ format =&#39;%s&#39;;
中有%d个猴子echo sprintf($ format,$ num,$ location);
在您的查询中没有格式化字符串,因此您可以执行以下查询:
$ blogs = $ wpdb-&gt; get_results(&#34; SELECT * FROM $ wpdb-&gt; blogs WHERE spam =&#39; 0&#39; AND deleted =&#39; 0&#39; and archived =&#39; 0&#39;和public =&#39; 1&#39;&#34;);