on top marketing placeholder

Today I’m going to share an idea that saved my team thousands of hours. 

This works well for service based businesses that need a lot of location pages. 

Directory websites that target a bunch of locations or similar services.

And it even works for affiliate websites, when used intelligently

In fact, any set of pages or achieves you have that require similar content will benefit from this approach if your team are currently using a tool to generate spun content and then manually putting it into your website. 

And it’s easy if you know about PHP if conditions

It’ll be a lot easier for you to understand this if you watch this video:

In it I explain how to create if conditions to show certain content based on the id of the page, the number of posts in an archive and more.

And although I haven’t tested the following code on a live site, this is the sort of thing I do:

Output code based on the post ID

<?php 
$post_id = get_the_ID(); 
?>

<?php if ( $post_id % 2 == 0 ) { ?>
 
Variation 1

<?php } else { ?>

Variation 2

<?php } ?>	

If the ID is even, then the code within the curly braces “{” and “}” following the “if” statement will be executed, which in this case is “Variation 1”. If the ID is odd, then the code within the curly braces “{” and “}” following the “else” statement will be executed, which in this case is “Variation 2”.

Output code based on number of posts in a loop

<?php
	if ( have_posts() ) :
	/* Start the Loop */
		while ( have_posts() ) : the_post(); ?>
			POST CODE HERE
<?php 
		$postCounter++;
		endwhile;
	endif; ?>


	<?php if($postCounter > 10) { ?>Variation 1<?php } elseif($postCounter > 7) { ?>Variation 2<?php } elseif($postCounter > 5) { ?>Variation 3<?php } elseif($postCounter > 3) { ?>Variation 4<?php } else { ?>Variation 5<?php } ?>

After the loop, the code uses an if statement to check the value of “$postCounter” and display a different variation of content depending on the number of posts displayed.

If more than 10 posts have been displayed, it will show “Variation 1”; if between 8-10 posts have been displayed, it will show “Variation 2”; if between 6-7 posts have been displayed, it will show “Variation 3”; if between 4-5 posts have been displayed, it will show “Variation 4”; otherwise, it will show “Variation 5”.

Output code based on whether the second number of the post ID is odd or even

<?php 
$post_id = get_the_ID(); 
$second_num = substr($post_id, 1, 1);
?>

<?php if ( $second_num % 2 == 0 ) { ?>
Variation 1
<?php } else { ?>
Variation 2
<?php } ?>

We are using the “substr()” function to extract the second digit of the ID and store it in a variable called “$second_num”.

The code then uses an if statement to check whether the value of “$second_num” is an even number. If it is, the code within the curly braces “{” and “}” following the “if” statement will be executed, which in this case is “Variation 1”. If it’s not even, the code within the curly braces “{” and “}” following the “else” statement will be executed, which in this case is “Variation 2”.

Output code based on if the ID is odd or even and what the first letter of the title is

<?php 
$post_id = get_the_ID(); 
$firstChar = substr(get_the_title(), 0, 1);
?>


<?php if ( $post_id % 2 == 0 ) { ?>
	<?php if ($firstChar == 'a') { ?> 
Variation 1
	<?php } else if ($firstChar == 'b') { ?> 
Variation 2
	<?php } ?>
<?php } else { ?>
	<?php if ($firstChar == 'a') { ?> 
Variation 3
	<?php } else if ($firstChar == 'b') { ?> 
Variation 4
	<?php } ?>
<?php } ?>	

This code is using the “substr()” function to extract the first character of the title of the current post or page and store it in a variable called “$firstChar”, and using the value of the post ID to determine whether the ID is even or odd.

Going through each letter of the alphabet (twice) will give us 52 variations.

How Are You Going To Use This?

If used correctly, this can be a game changer for your website. So give some thought to how you can use this to grow your traffic.

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's Grow Your Business

Need help marketing your business online?

Get Free Quote