我在WordPress上安装了很多次wordpress,通过SVN和替换文件夹.数据库始终保持不变。突然,来自SVN的新副本无法在两台不同的机器上工作,下面的代码来自wp调查和测试工具
function wpsqt_main_site_quiz_page($atts) {
extract( shortcode_atts( array(
'name' => false
), $atts) );
if ( !$name ){
require_once WPSQT_DIR.'/pages/general/error.php';
}
require_once WPSQT_DIR.'/includes/site/quiz.php';
ob_start();
wpsqt_site_quiz_show($name);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode( 'wpsqt_page' , 'wpsqt_main_site_quiz_page' );// Deprecated and will be removed
add_shortcode( 'wpsqt_quiz' , 'wpsqt_main_site_quiz_page' );如果我使用echo查看代码的到达位置,则在函数内部未到达add_shotcode,页面只显示以下内容:
[wpsqt_quiz name="test"]而不是用预期的quiz.php替换它。
现在我删除了数据库,得到了wordpress和插件的新安装,当然一切都很好。如果我得到的SVN版本,这不是所有的修改(它只是得到一个插件-魔术场-和一个定制的主题),删除插件,并再次安装,它仍然不能工作!
这里有什么问题吗?使add_shortcode工作所需的一切是什么?
发布于 2011-02-16 23:09:54
那个问题从昨天起就一直困扰着我。最后找出了原因,(现在)显然是在定制模板上。
标头包括对query_posts的调用,据推测,每次页面加载只能调用一次。然后,wp_reset_query来到了营救。但是等等!这两个函数似乎都被废弃了,这两个函数都不应该使用!相反,我们应该始终使用查询对象。
所以,这是可行的,但这是错误的
<?php query_posts('showposts=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?> ,这是正确而恰当的方式,
<?php $r = new WP_Query(array('showposts' => '10', 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1)); ?>
<?php if ($r->have_posts()) : while ($r->have_posts()) : $r->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endwhile; endif; ?> 否则,页面上的后续query_posts本身将无法正确加载,因此不会调用页面中的[wpsqt_quiz name="test"] (在页面post中)。
而且,似乎无法将[wpsqt_quiz name="test"]添加到模板页面中。
就这样。
https://stackoverflow.com/questions/5021340
复制相似问题