I Webseite mit Wordpress Bootstrap haben:Bootstrap Wordpress - PHP-Schleife falsche Reihenfolge der Spalten pro Zeile
http://www.obra-93.hr/zavrseni-projekti/
Ich habe Portfolio mit Elementen pro Zeile. Der Code für die Schleife 3 Elemente pro Zeile (totaly 20 Elemente) ist unten:
<div class="container">
<div class="row vrow">
<?php // slideshow
$args_projekti = array(
'showposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'post_type' => 'projekti',
'post_status' => 'publish',
'cache_results' => false,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
$projekti = new wp_query($args_projekti);
$p=0;
if ($projekti->have_posts()):
?>
<?php
while ($projekti->have_posts()):
$projekti->the_post();
$post_id = get_the_ID();
?>
<div class="col-xs-12 col-sm-4 col-md-4">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('projekt-thumb', array('class' => 'img-responsive fade center-block'));?></a>
<h3 class="text-center"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
</div>
<?php if($p%3===0){echo '</div><div class="row vrow">';} ?>
<?php $p++; endwhile; endif; wp_reset_query(); ?>
</div>
</div>
meine erste und letzte Zeile nicht richtig arbeitet. Warum?
Danke!
geändert if ($ p% 3 === 0) zu if ($ p% 3 === 1) - besser, aber ist das Lösung? – Fritex
Sie wollen wahrscheinlich '(($ p + 1)% 3 === 0)' –
Oder setzen Sie einfach Ihre '$ p = 1;';) Auch dort sind viele ähnliche Antworten und Fragen da draußen. [Zum Beispiel] (http://stackoverflow.com/questions/31787431/wrapping-every-3-elements-in-a-loop-leaves-an-empty-wrapper/) –