Jump to content

Recommended Posts

Hi

 

Can some help me with this bit of code please.

 

I am trying to reduce duplicate content on a shopping cart.

 

If a product is in more than one category in the shop then this is indexed as two pages and in turn is classed as duplicate content

 

The urls would be

/catalog/product_info.php?cPath=45&products_id=5651

‎‎/catalog/product_info.php?products_id=5651‎

 

I have reduced the duplicate content by blocking the page with a cpath number by doing this

 

 

<?php if ($_GET["cPath"] != '' ") {

 

echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW">' ;

 

} ?>

 

The trouble is some URLs dont display a number so this doesnt work.

 

/catalog/product_info.php?cPath=&products_id=5651

‎‎/catalog/product_info.php?products_id=5651‎

 

Is it possible to say - if cPath doesnt equal a number then display the NoINDEX

 

Or any other suggestion would be appreciated

 

Thanks

Gary

Link to comment
https://forums.phpfreaks.com/topic/137249-check-for-a-number/
Share on other sites

Looks like you're using osCommerce.

 

A way to check would be to go to the products_to_categories table for the products that don't have a cPath in the URL and see if they have a category.  You could do this manually and check a couple or just write a SQL query to check.

Link to comment
https://forums.phpfreaks.com/topic/137249-check-for-a-number/#findComment-717000
Share on other sites

Thanks for the reply.

 

Yes I am. I have checked this table and they all have a cpath listed. I think the software cant print out the cpath if its in more than two places. Presumably it has two cpaths because its in two places so the code doesnt display one or the other, just nothing.

 

This is why the cpath is empty in the URL

Link to comment
https://forums.phpfreaks.com/topic/137249-check-for-a-number/#findComment-717010
Share on other sites

Then why not grab the product_id and check it against the products_to_categories table.  Here's how you would check if the product were in 0, 1, or more than 1 categories:

 

if(isset($_GET['products_id'])) {

$prod_id = $_GET['products_id'];
$sql = "SELECT * FROM products_to_categories WHERE products_id = $prod_id";
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($result);

if($num > 1) {
   echo "This product is in MORE than 1 category!";
} elseif ($num == 1) {
   echo "This product is in ONLY 1 category!";
} else {
   else "This product ISN'T in any categories!";
}
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/137249-check-for-a-number/#findComment-717033
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.