• Resolved gillesbertaux

    (@gillesbertaux)


    Hi !

    Here’s my problem: I would like to add a class “current” to the first of the three post retrieved using a query. When those elements don’t have the “current” class they have a display:none attribute.

    Here’s the code I have so far by researching on the forum:

    <ul>
    <?php $blog_slider = new WP_Query( 'showposts=3' ); ?>
    <?php while ($blog_slider -> have_posts()) : $blog_slider -> the_post(); ?>
    <li class="slide tt-blog-slide <?php if( $blog_slider->current_post == 0 ) echo 'current-blog-slide';?>">
        <article class="tt-blog-text">
    	<div class="wrapper">
    	   <h2 class="tt-blog-title">From the Blog: <?php the_title(); ?></h2>
    	   <p class="tt-blog-subtitle subtitle-white"><?php echo substr(strip_tags($post->post_content), 0, 150);?></p>
    	   <a class="button-light-white" href="<?php the_permalink() ?>">Read Blog</a>
    	</div>
       </article>
    </li>
    <?php endwhile; ?>
    </ul>

    (each li is a slide to a slider.)

    But the posts don’t display at all.

    What am I doing wrong ?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter gillesbertaux

    (@gillesbertaux)

    Nevermind, I think I wrote wrong the name of the class.

    Here’s the working code :

    <?php $blog_slider = new WP_Query( 'showposts=3' ); ?>
    					<?php while ($blog_slider -> have_posts()) : $blog_slider -> the_post(); ?>
    					<li class="slide tt-blog-slide <?php if( $blog_slider->current_post == 1 ) echo 'current-slide-blog';?>">
    						<article class="tt-blog-text">
    							<div class="wrapper">
    								<h2 class="tt-blog-title">From the Blog: <?php the_title(); ?></h2>
    							 	<p class="tt-blog-subtitle subtitle-white"><?php echo substr(strip_tags($post->post_content), 0, 150);?></p>
    							 	<a class="button-light-white" href="<?php the_permalink() ?>">Read Blog</a>
    						 	</div>
    						</article>
    					</li>
    					<?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Styling first Post in Slider’ is closed to new replies.