好的,所以我尝试读取您的代码,但失败了,并将其重新格式化为当前无法读取,任何错误都会被这种无法读取性所掩盖。我无法强调正确缩进和遵循标准化格式的重要性,以使您的生活更加轻松:
<?php
$featured_class = \'et_cycle\';
$tag = \'ul\';
$attr = \'class\';
if($responsive){
$featured_class = \'flexslider\' . $featured_auto_class;
$tag = \'div\';
$attr = \'id\';
}
?>
<div id="featured" class="<?php echo $featured_class; ?>">
<a id="left-arrow" href="#"><?php esc_html_e( \'Previous\', \'Aggregate\' ); ?></a>
<a id="right-arrow" href="#"><?php esc_html_e( \'Next\', \'Aggregate\' ); ?></a>
<?php
echo \'<\'.$tag.\' \'.$attr.\'="slides">\';
global $ids;
$ids = array();
$arr = array();
$i=0;
$featured_cat = get_option( \'aggregate_feat_cat\' );
$featured_num = (int) get_option( \'aggregate_featured_num\' );
$query_args = array();
if ( get_option( \'aggregate_use_pages\' ) == \'false\' ){
// set which slug in custom taxonomy TOP it should filter
$query_args = array(
\'showposts\' => $featured_num,
\'top\' => \'billboard\'
);
}else {
global $pages_number;
if ( get_option( \'aggregate_feat_pages\' ) <> \'\' ){
$featured_num = count( get_option( \'aggregate_feat_pages\' ) );
} else{
$featured_num = $pages_number;
}
query_args = array(
\'post_type\' => \'page\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'post__in\' => (array) get_option( \'aggregate_feat_pages\' ),
\'showposts\' => (int) $featured_num
);
}
// needs to die, use WP_Query instead
query_posts($query_args);
if ( have_posts() ) {
while ( have_posts() ) {
global $post;
// START custom first post
if ( !$first_time ) {
$post_id = 105; // This is the ID of the first post to be displayed on slider
$post = get_post( $post_id );
$first_time = 1;
}else{
the_post(); // END custom first post
}
if ( $responsive ) {
echo \'<li\';
}else {
echo \'<div\';
}
echo \' class="slide">\';
$width = $responsive ? 960 : 958;
$height = 340;
$small_width = 95;
$small_height = 54;
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, \'\', $titletext, $titletext, false, \'Featured\' );
$arr[$i][\'thumbnail\'] = get_thumbnail( $small_width, $small_height, \'\', $titletext, $titletext, false, \'Small\' );
$arr[$i][\'titletext\'] = $titletext;
$thumb = $thumbnail["thumb"];
print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, \'\' );
?>
<div class="featured-top-shadow"></div>
<div class="featured-bottom-shadow feat<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>"></div>
<div class="featured-description">
<div class="feat_desc">
<h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt(); echo string_limit_words( $excerpt, 20 ); ?></p>
</div>
</div> <!-- end .description -->
<?php if ( $responsive ) { ?>
</li> <!-- end .slide -->
<?php } else { ?>
</div> <!-- end .slide -->
<?php } ?>
<?php $ids[] = $post->ID; $i++;
}
}
wp_reset_query();
echo \'</\'.$tag.\'>\';
?>
</div> <!-- end #featured -->
您会注意到,我做了一些简化,并替换了if语句,因此它们都使用
{}
而不是一堆速记和标准。
这里有很多问题,最后一个问题是wp\\U reset\\u query,最大的一个问题是query_posts
.
我强烈建议您不要使用query\\u帖子,而是使用WP_Query
或get_posts
.
罪魁祸首是你的循环:
while ( have_posts() ) {
global $post;
// START custom first post
if ( !$first_time ) {
$post_id = 105; // This is the ID of the first post to be displayed on slider
$post = get_post( $post_id );
$first_time = 1;
}else{
the_post(); // END custom first post
}
这里我们看到了post循环的开始,它检查是否有其他post,然后调用
the_post
向前推进。
然而,当第一次发帖时,你不会打电话the_post
, 因此循环无法前进。这不是循环应该如何工作,您应该always 呼叫the_post
不管
相反,我建议你在你的查询中指定不要包含105号帖子。(我也会避免硬编码post ID,它可能并不总是105)。
因此,首先,使用post__not_in
查询中的参数,例如:
$query_args[\'post__not_in\'] = array(105);