• Resolved windofchange87

    (@windofchange87)


    Hi everyone, I’m new to wordpress, I’m trying to create a custom theme.
    I’ve inserted a slider with images of a specific category now I would need to take individual images from different categories for sections.
    thanks
    this is the code:

    <?php get_header(); ?>
    
    <?php if(is_front_page()) {?>
      <?php query_posts('cat=7'); ?>
    
      <!-- Wrapper for slides -->
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
    
      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $i++;?>
      <?php if($i==1) { ?>
        <div class="item active">
      <?php } else { ?>
        <div class="item">
        <?php } ?>
        <?php if(has_post_thumbnail()) { 
    		the_post_thumbnail('full', array('class' => "img-responsive tales"));
    	?>
          
        <?php } ?>
        </div>
    	
        
    	<?php endwhile; endif;?>
        
      </div>
    
    </div>
    <?php } wp_reset_query(); ?>
    
    </div>
    <!-- sections -->
    <div class="col-sm-4 thumbnail">
        <img class="img-responsive" src="//dx35vtwkllhj9.cloudfront.net/woodyallen/woody-allen/images/cafe_society_tout.jpg" />
        <div class="caption post-content">Lorem ipsum dolor sit amet</div>
    </div>       
    <div class="col-sm-4 thumbnail">
        <img class="img-responsive" src="//dx35vtwkllhj9.cloudfront.net/woodyallen/woody-allen/images/cafe_society_tout.jpg" />
        <div class="caption post-content">Lorem ipsum dolor sit amet</div>
    </div>       
    <div class="col-sm-4 thumbnail">
        <img class="img-responsive" src="//dx35vtwkllhj9.cloudfront.net/woodyallen/woody-allen/images/cafe_society_tout.jpg" />  
        <div class="caption post-content">Lorem ipsum dolor sit amet</div>      
    </div>   
    
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Use objects of the WP_Query class to get posts of a particular category. You can then loop through the results much like the standard WP Loop, except instead of something like if ( have_posts()) you do if ( $query->have_posts()) where $query is the object of the WP_Query class you just instantiated.

    FYI, the use of query_posts() is strongly discouraged. There is really no reason for it other than reverse compatibility. I suggest you also use an object of WP_Query in this case as well. You’ll need to modify the template tags a little, and the reset for WP_Query is wp_reset_postdata()

    Thread Starter windofchange87

    (@windofchange87)

    thank you so much

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘category’ is closed to new replies.