•  
Posts Tagged ‘the loop’

Adding a external file after the first post

By Austin On April 9, 2009 No Comments

How might you display a Google ad after the first post or anything you like? It is very simple. You just need to add the variable $loopcounter in the Loop. If the $loopcounter is less than or equal to 1, then include your option. Check out the code:

<?php if (have_posts()) : while (have_posts()) : the_post(); $loopcounter++; ?> // your loop <?php if ($loopcounter <= 1) { include (STYLESHEETPATH . '/you-file.php'); } ?> <?php endwhile; ?> <?php else : ?> <?php endif; ?>

Pretty simple huh. Well in the $loopcounter line, you may change the include to point to any file or maybe

Click here to continue reading


Echo Images inside a Post into the Loop

By Austin On December 5, 2008 7 Comments

Here is a useful trick. Want to call or echo an image into your blog post with our using the custom fields? Well this could be tricky, but I know of a way.

All you have to do is print these lines of code into your
index.php or home.php inside the loop:

<?php $id =$post->ID; $the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id"); $home = get_option('home'); $pattern = '!<img.*?src="'.$home.'(.*?)"!'; preg_match_all($pattern, $the_content, $matches); $image_src = $matches['1'][0]; ?>

then after write:

<?php if($image_src != '') { ?> <a href="<?php echo the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a><br /> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $image_src; ?>"Click here to continue reading


StylizedWeb: query_posts() Pagination Problem

By Austin On November 29, 2008 No Comments

I was having an issue getting my pagination to work on my ShowCase page. I did a quick search and found a good solution. Check out this link, over at Stylized Web. Click here to continue reading