2
function Sail_wp_get_related_posts(){
global $wpdb, $post;
if(!$post->ID){return;}
$now = current_time('mysql', 1);
$tags = wp_get_post_tags($post->ID);
$taglist = "'" . $tags[0]->term_id. "'";
$tagcount = count($tags);
$m=1;
if ($tagcount > 1) {
for ($i = 1; $i < $tagcount; $i++) {
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
}
}
......
我把代码中functions.php
锉的调试问题:显示Notice: Undefined offset: 0
。
如何纠正它?谢谢。
这太复杂了。我可以在$ taglist =“'”之前创建一个条件。 $标签[0] - > term_id。 “'”;像if($ tags) – enjoylife
@enjoylife:我确实提出了一个条件。我只是说你需要在该行之前检查'$ tags'的长度。 – icktoofay
是的我也怀疑你的for循环for'($ i = 1; $ i <$ tagcount; $ i ++){'需要为'($ i = 0; $ i <$ tagcount; $ i ++){' – drew010