Forum Moderators: coopster
I wonder if anyone can help? I need to noindex our archive pages
We use this in the head of our index.php
<?php
if (is_home() && ($paged <= "1")) {
echo "<meta name=\"robots\" content=\"index,follow\"/>\n";
} else {
echo "<meta name=\"robots\" content=\"noindex,follow\"/>\n";
}
?>
Which works very well on page/2/ for eg, however our archive pages start late-deals/2006/12 and these pages need the noindex,follow,
I cannot get the noindex tag to drop in....
Kind regards
Pete
Now instead of seeking $page (which may be tough depending on your site structure), I would suggest to build a flag of some kind and check this flag on top of every page (on some include file perhaps)
Now your code would look like
if ($flag=="Y")
{
// noidex,follow
}
else
{
// index,follow
}
Now this can be tricky (based on the info/data you have for each page), but it's an alternative
I may be being a bit thick here, but can you show me an example of what the include should contain, also we still need to keep the noindex in page/2 and so on
As a fall back is there a way we can add the code to our original php
if (is_home() && ($paged <= "1")) and add the 2006 2005 catch all for noindex.
I tried this and got tstring error && ($2006d <= "1")
Kind regards
Pete
Secondly you do not need the quotes around the "1" in your conditional since the value you are comparing should contain an integer and not a string.
$invalid_years = array("2005","2006");
$invalid_months = array("1","3","5","11");
$year_to_check = 2007;
$month_to_check = 1;
if (in_array($year_to_check, $invalid_year) && in_array($month_to_check, $invalid_month))
{
// noindex
}
else
{
// index
}
Of courc you will have to modify your code to create the invaid arrays