gpt4 book ai didi

php - array_pop()期望参数1通过分类法代码在Wordpress相关文章中进行数组排列

转载 作者:行者123 更新时间:2023-12-03 08:24:06 24 4
gpt4 key购买 nike

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

Warning: array_pop() expects parameter 1 to be array, null given in ... on line 34

I get the following error when using the following function. The output of the function works as expected except the error shows up before the output.

<?php 
global $post;

//Get the terms for the current post
$terms = get_the_terms( $post->ID , 'character', 'string');
echo $terms[1];
$potentials = array();
$c = 0;
$totalFound = 0;

//Gather your posts for each term
foreach($terms as $term){
$q = array(
'character' => $term->slug, //term to retrieve from custom taxonomy
'numberposts' => 3, //limit to 4 posts
'post_type' => 'videos', //get only posts
'exclude' => $post->ID //exclude current post
);
$posts = get_posts($q);
$totalFound+= count($posts);
$potentials[$c++] = array_reverse($posts);
}

$count = 0; //The number of good posts we've found
$index = 0; //Number of posts we've tried
$max = $totalFound > 3 ? 3 : $totalFound; //The max we can find
$posts = array();

//Now pick one post from each term until we reach our quota,
//or have checked them all
while($count < $max){

//Pop off a post to use
$rpost = array_pop($potentials[$index++]);

//if we got a post (if there was one left)
if($rpost){
//don't take duplicates
if(!isset($posts[$rpost->ID])){
$posts[$rpost->ID] = $rpost;
$count++;
}
}
$index = ($index % 3); //rotate through the 4 term arrays
}
foreach($posts as $post){
setup_postdata($post);
$exclusive = get('aoexclusive_yes');
if(!$exclusive) {$exclusive = null;} else {$exclusive = 'exclusive';}
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "video-thumb" );
?>
<div class="thumb-post<?php echo ' '.$exclusive; ?>">
<?php if($image) { ?>

<a class="featured-image" href="<?php the_permalink(); ?>"><img src="<?php echo $image[0]; ?>" /></a>
<?php } else { ?>

<a class="featured-image" href="<?php the_permalink(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/assets/images/default.jpg" /></a>
<?php } ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php ao_post_meta(); ?>

</div>
<?php } ?>

Does anyone have any experience with this error or see what might be causing it?

Code originally came from http://wordpress.org/support/topic/custom-taxonomy-related-posts-query

更新:

上面的代码非常不完善。这个插件可以完美地工作:

http://pippinsplugins.com/write-a-better-related-posts-plugin-for-custom-taxonomies/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com