WordPress.org

Ready to get started?Download WordPress

Forums

Remove class from first post listed?? (3 posts)

  1. bencharity
    Member
    Posted 4 years ago #

    I am trying to create a slider that automatically pulls posts from a certain category.

    (See how it will eventually function here: http://benjamincharity.com/freelance/)

    It needs to be set up like this (notice the style 'display:none' on all except first):

    <div id="featured">
       <div id="loopedSlider">
    
          <ul class="nav-buttons">
               <li><a href="#" class="previous">P</a></li>
    	   <li><a href="#" class="next">N</a></li>
          </ul>
    
          <div class="container">
    	  <div class="slides">  
    
                <div id="slide1" class="slide">
                      SLIDE 1 CONTENT HERE
    	    </div>  <!-- end .slide -->
    
                <div id="slide2" class="slide" style="display:none;">
                      SLIDE 2 CONTENT HERE
         	    </div>  <!-- end .slide -->
    
                <div id="slide3" class="slide" style="display:none;">
                      SLIDE 3 CONTENT HERE
    	    </div>  <!-- end .slide -->
    
    	 </div>  <!-- end #slides -->
          </div><!-- .container ends -->   
    
    		<ul class="pagination">
    			<li><a href="#">1</a></li>
    			<li><a href="#">2</a></li>
    			<li><a href="#">3</a></li>
    			<li><a href="#">4</a></li>
    		</ul>	
    
        </div>  <!-- .content ends -->
    </div>  <!-- #featured ends -->

    So I changed the style addition to class="displaynone" and used css to make that class display:none. I am just not sure how to either add that class to all of the slide divs other than the first, or remove that class from only the first.

    Right now I have this code (I have added the displaynone class already, so in this example I would need to remove this class on the first item):

    <div id="featured">
    
        <div id="loopedSlider">
    
       	 <ul class="nav-buttons">
    		 <li id="p"><a href="#" class="previous"><img src="<?php bloginfo('template_url');?>/images/arrow-circle-left.png" alt="<" height="50px" width="50px" /></a></li>
    		 <li id="n"><a href="#" class="next"><img src="<?php bloginfo('template_url');?>/images/arrow-circle-right.png" alt=">" height="50px" width="50px" /></a></li>
    	  </ul>
    
    	 <div class="container">
    		 <div class="slides">  
    
    <?php
    query_posts("cat=16");
    
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0;
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
      <div id="post-<?php the_ID(); ?>" class="slide displaynone">
    
      <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    
     <div class="entry">
       <?php the_content('<span class="moretext">[continue reading...]</span>'); ?>
     </div>  <!-- end .entry -->
    	</div>  <!-- end .slide -->
    <?php endwhile; ?>
    
    		 </div>  <!-- end #slides -->
    	    </div><!-- .end container -->   
    
    		<ul class="pagination">
    			<li><a href="#">1</a></li>
    			<li><a href="#">2</a></li>
    			<li><a href="#">3</a></li>
    			<li><a href="#">4</a></li>
    		</ul>	
    
          </div>  <!-- end #loopedSlider -->
    
    </div>  <!-- end #featured -->

    I am still trying to learn the ins and outs of PHP so I am quite lost on this. Any help would be so greatly appreciated as my site is almost finished except for this!

    Thanks in advance,
    Benjamin

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

  3. bencharity
    Member
    Posted 4 years ago #

    Thanks alchymyth!

    However, using the code suggested (below) my entire page doesn't render.

    Also,
    If I want to pull only from a certain category, where would I put that call?

    Using this:

    <?php if (have_posts()) : ?>
    <?php $post = $posts[0]; $c=0;?>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php $c++;
    if( $c == 1) :?>
    <h1>The first post on the main index page</h1>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    
    <?php else :?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endif;?>
    
    <?php endwhile; ?>

    I was using this:

    <?php
    query_posts("cat=16");
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0;
    ?>

    How would I call category 16 in the above code?

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic