• I have created a feature slider with the ultimate goal to be:
    Display 5 recent posts using a custom field called “featured_article”
    Allow a sticky post to be promoted to the slider while still maintaining only 5 total slides (4 featured and 1 sticky).

    The slider works fine when there are only the featured_article posts. The problem, when a sticky post is first published, only 4 total slides show. It remains this way until 5 new featured_article are posts are live.

    Let me know if you need more clarification.

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been damaged by the forum’s parser.]

    <?php
    $sticky = get_option( 'sticky_posts' );
    // Count how many there are, if any
    $count = count( $sticky );
    if($count >= 1){$postsperpage = 4;}else{$postsperpage = 5;}
    $args = array(
    	'posts_per_page' => $postsperpage,
    	'post_status' => 'publish',
    	'meta_key' => 'featured_article',
    	'post_in' => $sticky
        );
    $featured = new WP_Query( $args );
    ?>
    
    <section class="featured" id="featured-slider">
    	<ul class="bxslider">
        <?php while( $featured->have_posts() ) : $featured->the_post(); ?>
    	  <li id="post-<?php the_ID(); ?>" <?php if(is_sticky()) { echo "class='sponsored-main featured'"; }else{echo "class='featured'";}?>>
    	  	  <figure style="position:relative; z-index: 1;"><a>"><?php echo get_the_post_thumbnail() ?></a></figure>
    			<div class="slider-content">
    				<h1 class="featured-title">
    					<a>">
    						<?php the_title(); ?>
    					</a>
    				</h1>
    				<p><?php new_excerpt(150); ?></p>
    			</div>
    
        <?php endwhile; wp_reset_query(); ?>
    
    </section><!-- end slider -->

    [Moderator Note: No bumping, thank you.]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Promote sticky to slider and limit number of slides’ is closed to new replies.