Use Loop In Wordpress -Wordpress Hacks

Digg this

1)The Loop is perhaps the most important thing one needs to understand when customizing WordPress theme. Any HTML or PHP code placed between where The Loop starts and where The Loop ends will be used for each post. When WordPress documentation states “This tag must be within The Loop”, such as for specific Template Tag or plugins, this is The Loop.

<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
// the code inside the loop
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>


1)Modifying Individual Posts In The Loop- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently.

2)Embed Google Ad in First WordPress Post- One of the more effective places to implement Google Adsense is after the first post, so you want to prevent your ad code from appearing after every single post, as WordPress would just loop and keep showing it. All you need to do is add this code inside the loop.


<?php if ($count == 1) : ?>
// Insert your Google AdSense code here
<?php endif; $count ; ?>

You can also publish the advertisement after the second post or the third etc. Just change:

“count == 1? to “count == 2?

Related Posts by Categories



Widget by Scrapur | Scrap Book

0 comments: