I thought, lets post about how "they" do it. This time, let me explain how some WordPress plugins seem to be able to recognize whether you are new or not, and then display a message accordingly. Usually, the message appears for the first 1-3 times someone visits, and says "subscribe"! And after that, it won't appear anymore.We are not going to do it WP plugin style, but rather for a product site, which has some great products. They want to display a message for the first 3 times, notifying the user that they have great products, with a link to their products page.
Let's get things rolling!
<?php
$say = "Welcome. We think you are new here, so you might not have seen our great <a href = 'productspage.php'>products</a>";
if(isset($_COOKIE['newguest']) && (int) $_COOKIE['newguest'] < 3)
{
$newval = (int) $_COOKIE['newguest'] + 1;
setcookie("newguest", "$newval", time()+60*60*24*365*10);
echo $say;
}elseif(!isset($_COOKIE['newguest'])){
setcookie("newguest", "1", time()+60*60*24*365*10);
echo $say;
}
?>
This is a snippet that you can add to your code easily. It will now disappear after three times, but just change the 3 into 2, and it will disappear after 2 times for example.
I hope you like it, and if you implement it somewhere, let us know!
Making Sales Making Money says on November 10, 2007
We1l I did try , but my theme didn't like it in the header, Wordpress or code is not my area of expertise, posted about that last night, More detailed installation instructions would help the people like me
koen (103) says on November 11, 2007:
As I said, it isn't really for WP, but if you want, I can create some code that will for sure work with WP (although, I'm wondering why it doesn't work *checks his WP installation with the script*).sarahG (34) says on November 11, 2007:
I would guess that it's because you didn't mention that setcookie() shouldn't be run after HTML output.


