herrfischer

Loop with sticky posts

Aug 26th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <section>
  2. <h2 class="style-line"><span>Aktuelles</span></h2>
  3. <div class="row aktuelles-index-4col aktuelles-index sameheight">
  4. <?php
  5. $sticky = count(get_option('sticky_posts'));
  6. // WP_Query arguments
  7. $main_loop = array (
  8. 'posts_per_page'         => 4 - $sticky
  9. );
  10.  
  11. // The Query
  12. $query = new WP_Query( $main_loop );
  13.  
  14. // The Loop
  15. while ( $query->have_posts() ) : $query->the_post(); ?>
  16. <article <?php post_class('col-md-3 col-sm-6 mbottom_xl sameheight-item') ?>>
  17.  
  18. <?php echo $sticky; ?>
  19. <header>                       
  20. <?php if (has_post_thumbnail( $post->ID ) ) { ?>
  21. <!-- YES, has an awesome article thumb -->
  22. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'img-m' );
  23. $image = $image[0];
  24. ?>
  25. <a href="<?php the_permalink(); ?>" class="hover-read home-aktuelles-thumb" style="background-color: <?php the_field('farbe_b','option'); ?>;">
  26. <figure style="background-image: url('<?php echo $image; ?>')"> </figure>
  27. </a>
  28. <?php } else { ?>
  29.  
  30. <!-- NO, has no article thumb, but hey ... -->
  31. <a href="<?php the_permalink(); ?>" class="hover-read home-aktuelles-no_thumb" style="background-color: <?php the_field('farbe_b','option'); ?>;">
  32. <div style="background-image: url(<?php the_field('logo','option');?>); background-color: #efefef;">
  33. <!-- ... hmmm ... show logo. -->                               
  34. </div>
  35. </a>
  36. <?php } ?>
  37.  
  38. <span class="meta"><?php include (TEMPLATEPATH . '/meta.php' ); ?></span>
  39. <h3>
  40. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  41. </h3>
  42. </header>
  43. <?php the_excerpt(); ?>
  44. <footer><a href="<?php the_permalink();?>" class="farbe-b button-wide button-mtop"><span>Mehr Info</span></a></footer>
  45. </article>
  46.  
  47. <?php endwhile; wp_reset_postdata();
  48. ?>
  49. </div><!-- row -->
  50. </section>
Advertisement
Add Comment
Please, Sign In to add comment