Ik heb de volgende php code in Wordpress om elke 3e post op de homepage de class "contentbox-right" te geven ipv "contentbox"
Er zit een foutje in, want hij plaats bij elke 1e post "contentbox-right" ipv de laatste. Ik heb geprobeerd te spelen met de code, maar zonder succes.PHP Code:
<?php $counter = 0; if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="contentbox<? if ( $count % 3 == 0 ) echo '-right' ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<span class="contentbox-link"><a href="<?php the_permalink() ?>">Lees verder</a></span>
</div>
<? $count++; ?>
<?php endwhile; ?>
Wie weet wat ik fout doe?
- Php foutje Wordpress
-
29-12-2012, 22:29 #1
- Berichten
- 576
- Lid sinds
- 18 Jaar
Php foutje Wordpress
-
-
30-12-2012, 02:42 #2
- Berichten
- 27
- Lid sinds
- 14 Jaar
Re: Php foutje Wordpress
Je variabelen wel goed gebruiken $counter of $count
En beginnen met 1 ipv 0
0 % 3 is namelijk ook 0
deze zou moeten werken:
PHP Code:$counter = 1;
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="contentbox<? if ( $counter % 3 == 0 ) echo '-right' ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<span class="contentbox-link"><a href="<?php the_permalink() ?>">Lees verder</a></span>
</div>
<? $counter++; ?>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
-
30-12-2012, 14:06 #3
- Berichten
- 576
- Lid sinds
- 18 Jaar
Re: Php foutje Wordpress
Enorm bedankt! Dit werkt super. Ik ben geen held hierin, dus ben er heel blij mee.
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic