Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28
  1. #11
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    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:
    Code:
    // 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:
    Code:
    <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ); ?>" />
    <?php if (isset($canonicalLink) && $canonicalLink != '') { ?>
    <link rel="canonical" href="<?php echo $canonicalLink; ?>" />
    <?php } ?>
    
    <?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.

  2. #12
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

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

    Regards,
    Christian.

  3. #13
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    Quote Originally Posted by DrByte View Post
    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:
    Code:
    //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

  4. #14
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

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

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

    ? am I missing something?

  5. #15
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    Quote Originally Posted by DrByte View Post
    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!???

  6. #16
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    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/#######...nsemble-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...nsemble-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:

    PHP Code:
    <!-----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

  7. #17
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    OK narrowed this down now.

    I have also added this

    PHP Code:
    <?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..

  8. #18
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    Quote Originally Posted by CJPinder View Post
    Just a quick note, make sure you have applied this fix...
    http://www.zen-cart.com/forum/showpo...7&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??

  9. #19
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    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

  10. #20
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Need help calling variables - trying to set up my own canonical URL handling

    Quote Originally Posted by philip937 View Post
    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.

    Quote Originally Posted by philip937 View Post
    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.
    Quote Originally Posted by philip937 View Post
    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.
    Quote Originally Posted by philip937 View Post
    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.

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Need help with a couple of variables
    By BushyTea in forum General Questions
    Replies: 2
    Last Post: 12 Mar 2010, 03:36 AM
  2. Help Calling JQuery?!
    By tjohnson13 in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 9 Dec 2009, 06:24 PM
  3. Need a debug tool to read variables
    By ronlee67 in forum General Questions
    Replies: 4
    Last Post: 1 Jun 2009, 04:11 AM
  4. Need User Tracking To Help Display Variables
    By bumba000 in forum General Questions
    Replies: 0
    Last Post: 5 Jan 2008, 08:39 PM
  5. Replies: 8
    Last Post: 26 Apr 2007, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg