Integrate a counter into the loop
-
hi Guys
I am responsible for the website of our non-profit mini golf club. For this we use the Colormag theme. We would like to insert a couple of banners from our sponsoring members in the report overview. But don’t use a plugin. Because of the thief blockers. For this purpose, only image files should be shown and linked.
Basically I know how to do it. Simply install a counter and let it count up. After the 3rd, 5th and 7th blog post, the picture should then be inserted.
I wrote the counter in Index.php directly before the loop, set it to zero and let it count up from the loop at the beginning.
<Code>
index.php
<? php $ display = “0” / * set counter to zero * /?>
<? php if (have_posts ()):?>
…
</ Code>If I test the counter by echo command jn the content.php then before each post is 1. That shows me that the counter does not count up.
<Code>
content.phpThe counter code
<? php $ display; / * Counter starts counting * /?>
<article id = “post – <? php the_ID ();?>” <? php post_class (); ? >>
…
</ Code>The code for the ad looks like this:
<Code>
<? Php
if ($ display == 1) {echo “Ad 1”; }
elseif ($ display == 3) {echo “Ad 2”; }
elseif ($ display == 5) {echo “Ad 3”; }
else {}
?>
</ Code>What am I doing wrong? I assume that I inserted the counter in the wrong place in the theme. But which one is the right one. I do not know how to continue.
Could someone please give me some help?
With kind regards,
The page I need help with: [log in to see the link]
- The topic ‘Integrate a counter into the loop’ is closed to new replies.