当我的测试站点将调试设置为 false 时,一切都很好。当我去调试我的模板时,我看到以下错误:
Notice: Undefined variable: post in /home/xxxxxxx/public_html/wp-content/themes/twentyeleven-child/functions.php on line 15
Notice: Trying to get property of non-object in /home/xxxxxxxx/public_html/wp-content/themes/twentyeleven-child/functions.php on line 15
这是我的代码,但我不知道变量是什么或非对象的属性。
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)";
echo $excerpt;
}
这是我在模板中使用的循环:
<?php $postslist = get_posts('category=4&numberposts=3&order=DESC&orderby=post_date');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<div class="post_item">
<span class='side_date'><?php the_time('F j, Y'); ?></span><br />
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php excerpt(11); ?></div>
<?php endforeach; ?></div>
谢谢...