Forums / General Questions / Need help calling variables

Need help calling variables

Locked

Views: 6,386

Results 1 to 20 of 28
This thread is locked. New replies are disabled.
13 Mar 2010, 3:38 PM
#1
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Need help calling variables

Hi everyone,

I am currently working on some code that will add
<meta name="ROBOTS" content="NOINDEX,FOLLOW">

on linked product pages.

in the html_header.php file I have added:

<?php
include('includes/meta_noindex.php');
?>

where meta_noindex.php is:

$check_linked = mysql_query('SELECT master_categories_id from products WHERE products_id = '.$prod_id.'');
$check_result_row = mysql_fetch_row($check_linked);
$catid = $check_result_row[0];

if ( $catid == $current_category_id ) {
} else {
$meta = '<meta name="ROBOTS" content="NOINDEX,FOLLOW">';
echo $meta;
} 

only problem is that having the code in the html_header there is no reference to the variables:
$prod_id
$current_category_id

Can anyone advise what I could do to get this to work??

Cheers
Phil

Phil Rogers
A problem shared is a problem solved.

13 Mar 2010, 4:32 PM
#3
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

kobra:

Use Developer tools and search for use of $prod_id

https://www.zen-cart.com/tutorials/index.php?article=38
https://www.zen-cart.com/tutorials/index.php?article=39

I did, thats how I knew the variable was $prod_id ! I need to know how my code can know the same $prod_id value that the tpl_product_info_display.php outputs...

?

Phil Rogers
A problem shared is a problem solved.

13 Mar 2010, 10:52 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

You could use the built-in functionality for $robotsNoIndex by putting your code into the end of init_add_crumbs.php and reworking it to set $robotsNoIndex under the conditions you desire.

There are other discussions for handling canonical matters also discussed elsewhere on the forum.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

17 Mar 2010, 7:03 PM
#5
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

DrByte:

You could use the built-in functionality for $robotsNoIndex by putting your code into the end of init_add_crumbs.php and reworking it to set $robotsNoIndex under the conditions you desire.

There are other discussions for handling canonical matters also discussed elsewhere on the forum.

Thanks BrByte,

Any chance of a bit of guidance with the init_add_crumbs.php file?

I tried my code in the bottom and also inside the if (isset($_GET['products_id'])) { part, but neither had the desired affect.

My code has the correct logic, it compares the current category with the master and I set it to set the $robotsNoIndex, but it was doing this regardless for some reason?

Phil

Phil Rogers
A problem shared is a problem solved.

18 Mar 2010, 2:39 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

Actually, I take part of that back. I'd recommend just adding the following to the bottom of your init_category_path.php file:```
// set noindex, nofollow on linked products
if ($current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;

<https://www.zen-cart.com/tutorials/index.php?article=313>

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Mar 2010, 4:52 PM
#7
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

DrByte:

Actually, I take part of that back. I'd recommend just adding the following to the bottom of your init_category_path.php file:```
// set noindex, nofollow on linked products
if ($current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;

> <https://www.zen-cart.com/tutorials/index.php?article=313>

DrByte,

Thanks I almost got this working I think, however your suggestion seems to have 2 issues I can see so far (assuming I followed your instructions correctly?)

the noindex seemed to be included in the product in the  master category and not on the linked the opposite to the desired effect,

also after adding it i noticed its adding the noindex to tag to the category pages too :o(

here is what I did, perhaps you might point out if I have done it wrong?

so the edit to init_category_path.php file looks like this:

if ($current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;

Phil Rogers
A problem shared is a problem solved.

18 Mar 2010, 8:18 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

Maybe try this instead of what I posted earlier?```
if ($current_page != 'index' && isset($_GET['products_id']) && $current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;


Again, there are other discussions for more focused canonical handling already kicking around the forum.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Mar 2010, 10:23 PM
#9
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

Thats works perfect but its still does the opposite i.e sets

no index no follow on the master category and not the linked rather than the other way around??

I even went into my category link manager to check that the master cat that it should have been was actually set right and it was...

I'm trying to work out how your code is working? my original one compared the current category id with the master for the current product, is this how yours is working to?

I tried removing the ! as I thought it might reverse the logic but that just set noindex on both.

This is so close...

I have search around the forums and can't find any similar topics.

Phil Rogers
A problem shared is a problem solved.

18 Mar 2010, 11:15 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

I'm not sure why you're having any problem with it, since zen_get_products_category_id gives you the master, and $current gives you the current one, and it's already comparing those for mismatch.

This tests fine for me:```
//Robots no-index on product pages not using master_categories_id:
if ($current_page != 'index' && isset($_GET['products_id']) && $current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;

Although, it only deals with product pages, and not category pages.

However, as I've eluded to before, I'd recommend a different approach altogether: proper canonical handling.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

19 Mar 2010, 9:02 AM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

Here's a very basic start to doing canonical URL handling:

IT IS NOT RECOMMENDED TO ADD THIS TO AN ALREADY-INDEXED SITE WITHOUT FIRST CAREFULLY CONSIDERING THE CONSEQUENCES OF DOING SO!!!!

  1. At the bottom of init_category_path.php (replacing the ?> if any), add this: ```
    // CANONICAL HANDLING:
    // product pages:
    if (strstr($current_page, '_info') && isset($_GET['products_id'])) {
    $canonicalLink = zen_href_link($current_page, 'cPath=' . zen_get_generated_category_path_rev(zen_get_products_category_id($_GET['products_id'])) . '&products_id=' . $_GET['products_id']);
    }
    // category/prod-listing pages:
    if ($current_page == 'index' && isset($_GET['cPath'])) {
    $excludeParams = array('zenid', 'action', 'main_page', 'language', 'currency', 'typefilter', 'disp_order', 'page', 'sort', 'alpha_filter_id', 'filter_id');
    $canonicalLink = zen_href_link($current_page, zen_get_all_get_params($excludeParams));
    }
2. In /includes/templates/YOUR_TEMPLATE_FOLDERNAME/common/html_header.php
Add the 3 lines highlighted here, as shown:```
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ); ?>" />
[B]<?php if (isset($canonicalLink) && $canonicalLink != '') { ?>
<link rel="canonical" href="<?php echo $canonicalLink; ?>" />
<?php } ?>
[/B]
<?php
/**
 * load all template-specific stylesheets, named like "style*.css", alphabetically

There are some who may argue that the 'sort' or 'page' options should be removed from these exclusions. If you feel similarly, you're welcome to change it.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

19 Mar 2010, 10:47 AM
#12
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Need help calling variables

Just a quick note, make sure you have applied this fix...
http://www.zen-cart.com/forum/showpost.php?p=659717&postcount=28
...before using DrByte's code above. Without the fix the canonical URLs generated will not be consistent.

Regards,
Christian.

19 Mar 2010, 12:36 PM
#13
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

DrByte:

I'm not sure why you're having any problem with it, since zen_get_products_category_id gives you the master, and $current gives you the current one, and it's already comparing those for mismatch.

This tests fine for me:```
//Robots no-index on product pages not using master_categories_id:
if ($current_page != 'index' && isset($_GET['products_id']) && $current_category_id > 0 && $current_category_id != zen_get_products_category_id($_GET['products_id']) ) $robotsNoIndex = TRUE;

> Although, it only deals with product pages, and not category pages.
> 
> However, as I've eluded to before, I'd recommend a different approach altogether: proper canonical handling.

Hi DrByte,

OK I tried the code again.. this time..

with != this had the following effect:
1. if a product is linked it added noindex nofollow on the product in the master category
2. all linked products and non linked products had no meta tag

with == this had the following effect:
1. all linked products and non linked products had noindex nofollow
2. all linked products in master category had no tags

What I need to achieve is:
1. all linked products to have noindex nofollow
2. all master category products & non linked products to have no tag.

Phil

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 12:49 PM
#14
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

Going by my original logoc which worked when I was echoing onto product pages I thought this might work.. but its doesnt...

if (($_GET['master_categories_id']) != $current_category_id ) {
  $robotsNoIndex = TRUE;
}

? am I missing something?

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 1:17 PM
#15
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

DrByte:

Here's a very basic start to doing canonical URL handling:

IT IS NOT RECOMMENDED TO ADD THIS TO AN ALREADY-INDEXED SITE WITHOUT FIRST CAREFULLY CONSIDERING THE CONSEQUENCES OF DOING SO!!!!

...

I have just tried this one. Its perfect for what I need, but I am at a loss. For some reason it is doing the COMPLETE opposite on my site, its setting the canonical for the linked product not the master!???

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 1:41 PM
#16
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

Dr Byte,

I thought I would expand on this issue. OK here's why I am confused.

Two example products:

Master Category
http://www.fanciedress.co.uk/########-fancy-dress/7-piece-lady-bug-ensemble-p-1763

the ######## should be s e x y, I guess the forum doesnt like that word!

Linked Category
http://www.fanciedress.co.uk/animals-bugs-fancy-dress/7-piece-lady-bug-ensemble-p-1763

Looking in categories link manager I can see:
Yellow square next to ########-fancy-dress category id 27 - indicating Master

tick next to animals-bugs-fancy-dress category id 22 - indicating linked

To prove this I have added the following code for you to see at the bottom of the tpl_product_info_display.php page to echo the master category id:

<!-----bof master category id check-------->
<?
$check_linked = mysql_query('SELECT master_categories_id from products WHERE products_id = '.$prod_id.'');
$check_result_row = mysql_fetch_row($check_linked);
$catid = $check_result_row[0];

echo $catid;
?>
<!-----eof  master category id check-------->

as you can see on both urls, it displays id 27 as you'd expect.

However, when I add the code you gave me, it is adding <link rel="canonical" href="http://www.fanciedress.co.uk/animals-bugs-fancy-dress/7-piece-lady-bug-ensemble-p-1763" /> to both urls but that is the linked category url...

Am I being thick?

Please help, i'm now worried there is something wrong with my setup. but im pretty sure ive proved the right master cat id's are present...

Phil

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 2:01 PM
#17
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

OK narrowed this down now.

I have also added this

<?php
$tester = zen_get_products_category_id($_GET['products_id']);
echo $tester;
?>

You said that zen_get_products_category_id($_GET['products_id']) should be the master id, on mine its calling the linked...

look at the bottom of these urls, the first number is the master which is my db query calling and the second is the linked which zen_get_products_category_id is calling..

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 2:19 PM
#18
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

CJPinder:

Just a quick note, make sure you have applied this fix...
http://www.zen-cart.com/forum/showpost.php?p=659717&postcount=28
...before using DrByte's code above. Without the fix the canonical URLs generated will not be consistent.

Regards,
Christian.

I can't believe i didnt see your post!

I was indicating that the canonical URLs were setting as linked instead of the master I take it this fixes this!???

Does making this change affest anything else??

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 3:13 PM
#19
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Need help calling variables

Dr Byte,

I'm fairly confident after applying this fix:
http://www.zen-cart.com/forum/showpo...7&postcount=28
your code will work as you described. Before I do, can you explain what you ment by conciquences of implementing after indexing?

My understanding was that the next time google crawls that page with the new rel... etc, it will then know the main url...?

Is this not the case? is there a downside to this??

Cheers,
Phil

Phil Rogers
A problem shared is a problem solved.

19 Mar 2010, 4:16 PM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Need help calling variables

philip937:

I'm fairly confident after applying this fix:
http://www.zen-cart.com/forum/showpo...7&postcount=28
your code will work as you described. Before I do, ...There's no need to wait before applying that confirmed bugfix.

philip937:

can you explain what you ment by conciquences of implementing after indexing?You want to be sure that the canonical links it's generating are the ones you want it to produce.
philip937:

My understanding was that the next time google crawls that page with the new rel... etc, it will then know the main url...?I'll state it this way: The next time google crawls, it will be told about whatever canonical links you're generating, and will take action accordingly.
philip937:

Is this not the case? is there a downside to this??
The downside is that if it's generating canonical links that you don't want it to generate, it will rearrange its index the way you don't want it, and if you need to change something you'll have to wait for it to re-index again before it will fix whatever you want fixed, and it may take time for it to rebuild things the way you want them.

There are many rags/blogs that suggest not to just go throwing canonical urls onto pages without first verifying that it's doing what you want for your site.
There are many more that go on to say that they recommend not excluding sort or page number parameters, but then there are those that do.
The only consistent thing you'll find is that nobody really seems to know for sure. Even google doesn't spell it out exactly, but they usually don't anyway.
Hence my disclaimer.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.