Skip to content

Instantly share code, notes, and snippets.

@aslamhindko
Last active March 20, 2019 10:46
Show Gist options
  • Save aslamhindko/035d6920fb9e224f5f9bb07ce3bcc114 to your computer and use it in GitHub Desktop.
Save aslamhindko/035d6920fb9e224f5f9bb07ce3bcc114 to your computer and use it in GitHub Desktop.
(ye wordpress loop counter hain agar meri post type multiple ho tu use hogi)
<div class="container">
<div class="row">
<div class="col-md-12">
<?php
$q = new WP_Query(
array('post_type' => array('product'),
'post_status' => array('publish'),
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 3,
'service-category' => $category)
);
?>
<?php
$count = 1;
while ($q->have_posts()) : $q->the_post(); ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(),'full', true); ?>
<?php if ($count == '1'): ?>
<div class="col-md-4 service-box one">
<div class="col-sm-6 center">
<img src="<?php echo $thumbnail[0]; ?>" width="151" height="152" alt="icons">
</div>
<div class="col-sm-6">
<h3><?php the_title();?></h3>
<?php echo get_the_content();?>
</div>
</div>
<?php $count++ ?>
<?php elseif ($count == '2'): ?>
<?php $count++ ?>
<div class="col-md-4 service-box two center">
<div class="col-sm-12">
<img src="<?php echo $thumbnail[0]; ?>" width="89" height="89" alt="icons">
</div>
<div class="col-sm-12">
<?php the_content();?>
<a href=""><?php the_title();?></a>
</div>
</div>
<?php elseif ($count == '3'): ?>
<div class="col-md-4 service-box three">
<div class="col-sm-6">
<h3><?php the_title();?></h3>
<?php the_content();?>
</div>
<div class="col-sm-6 center">
<img src="<?php echo $thumbnail[0]; ?>" width="178" height="166" alt="icons">
</div>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</div>
</div>
<!-- Section 2 -->
<section class="service">
<div class="container">
<h5>TASTY & CRUNCHY</h5>
<h2>Choose & enjoy</h2>
<h4>Inspired by recipes and creations of world’s best chefs</h4>
<?php
$q = new WP_Query(
array('post_type' => array('packages'),
'post_status' => array('publish'),
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 5
));
?>
<?php
$count = 1;
while ($q->have_posts()) : $q->the_post(); ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(),'full', true); ?>
<?php if ($count == '1'): ?>
<div class="col-md-4">
<div class="service2">
<img src="<?php echo $thumbnail[0]; ?>" class="img-responsive" >
<aside><?php the_title();?></aside>
<?php echo get_the_content();?>
</div>
</div>
<?php $count++ ?>
<?php elseif ($count == '2'):
$count++; ?>
<div class="col-md-4">
<div class="service2">
<img src="<?php echo $thumbnail[0]; ?>" class="img-responsive" >
<aside><?php the_title();?></aside>
<?php echo get_the_content();?>
</div>
</div>
<?php elseif ($count == '3'):
$count++; ?>
<div class="col-md-4">
<div class="service2">
<img src="<?php echo $thumbnail[0]; ?>" class="img-responsive" >
<aside><?php the_title();?></aside>
<?php echo get_the_content();?>
</div>
</div>
<?php elseif ($count == '4'):
$count++; ?>
<div class="col-md-4 col-md-offset-2">
<div class="service2">
<img src="<?php echo $thumbnail[0]; ?>" class="img-responsive" >
<aside><?php the_title();?></aside>
<?php echo get_the_content();?>
</div>
</div>
<?php else: ?>
<div class="col-md-4">
<div class="service2">
<img src="<?php echo $thumbnail[0]; ?>" class="img-responsive" >
<aside><?php the_title();?></aside>
<?php echo get_the_content();?>
</div>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment