Okay so I tried to read your code, and failed, and reformatted it as it’s currently unreadable, and any errors are obscured by this unreadability. I cannot stress the importance of indenting correctly and following a standardised formatting for making your life infinitely easier:
<?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 -->
You’ll notice i made some simplifications and swapped out the if statements so they all use {}
rather than a muddle of shorthand and standard.
There are a number of issues here, the one at the end being wp_reset_query, and the biggest alarm bell being the use of query_posts
.
I strongly recommend you never use query_posts and instead use either WP_Query
or get_posts
.
The culprit here is your loop:
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
}
Here we see the beginning of your post loop, it checks if there are additional posts, then calls the_post
to advance forwards.
When the first post happens however, you don’t call the_post
, so the loop fails to advance. This is not how a loop should work, you should always call the_post
regardless.
Instead, I’d suggest you specify in your query not to include the post 105. ( I would also avoid hardcoding the post ID, it may not always be a 105 ).
So, to start with, use the post__not_in
parameter on your query, e.g.:
$query_args['post__not_in'] = array(105);