Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / What's The Easiest Way To Create A Direct Link In The Sidebox?

What's The Easiest Way To Create A Direct Link In The Sidebox?

Views: 8,807

Results 1 to 20 of 36
13 Jan 2016, 3:43 AM
#1
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

What's The Easiest Way To Create A Direct Link In The Sidebox?

Working on a new bookseller site, https://www.book-oasis.com. The owner wants the last two categories (http://book-oasis.com/index.php?main_page=index&cPath=7 and http://book-oasis.com/index.php?main_page=index&cPath=8) to redirect to different sites. Is there an easy way to do this?

Many thanks, in advance, for your assistance!!

13 Jan 2016, 4:06 AM
#2
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

well, i suppose it will all depend on which template you are using and what script is creating the url. most likely, i think you could modify:

includes/templates/YOUR_TEMPLATE/sideboxes/tpl_categories.php

from within that script you could add change the following line:

$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT.'&pg=store', $box_categories_array[$i]['path']) . '">';

to something like

if ($box_categories_array[$i]['path'] == 'cPath=7') {
      $content .= '<a class="' . $new_style . '"  href=\"www.somewhereawayfrombookoasis.com\">';
} else {
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT.'&pg=store', $box_categories_array[$i]['path']) . '">';
}

if that does not more work, i would look to see if your site has the following files:

includes/classes/categories_ul_generator.php
includes/classes/categories_ul_generator_template.php

if they are there, you might need to modify those files instead.

good luck!

13 Jan 2016, 4:35 AM
#3
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

This is the closest I've been able to find. I think it's what you were referring to; it just has that <div class> code inserted in it, which made finding it a real pain.

   $content .= '<div class="betterCategories"><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
  if ($box_categories_array[$i]['current']) {
    if ($box_categories_array[$i]['has_sub_cat']) {
      $content .= '<span class="category-subs-parent">';
      $content .= cat_with_pointer($box_categories_array[$i]['name'], 'down', $spacer);
      $content .= '</span>';
    } else {
      $content .= '<span class="category-subs-selected">';
      $content .= cat_with_pointer($box_categories_array[$i]['name'], 'nosub', $spacer);
      $content .= '</span>';
    }
  } else {
    if ($box_categories_array[$i]['has_sub_cat']) { 
    $content .= cat_with_pointer($box_categories_array[$i]['name'], 'right', $spacer); }
    else { 
    $content .= cat_with_pointer($box_categories_array[$i]['name'], 'nosub', $spacer); }
  }

To be perfectly honest, I'm scared to death to mess with it. I never understood php, and it's been a long time since I've worked with it. I'm not sure where I should add...whatever it is I'm supposed to add...let alone add it twice for two separate links. :-/

13 Jan 2016, 3:05 PM
#4
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK,
few things; when posting code on the forum, use square brackets with 'php' or 'code' inside of the brakets. and then end the code section again with the square brackets and a slash and the appropriate tag as the ending tag. it makes it much easier to read (and i'm sure there are notes on it somewhere). 2nd, make a backup of the code, prior to making any changes. this is not rocket science so as long as you can go back from where you came you should be fine.

from what you are posting i think you only need to change the first line. try changing the first line to the following lines and let us know how it goes:

if ($box_categories_array[$i]['path'] == 'cPath=7') {
    $content .= '<div class="betterCategories"><a class="' . $new_style . '" href=\"www.somewhereawayfrombookoasis.com\">';
} elseif ($box_categories_array[$i]['path'] == 'cPath=8') {
    $content .= '<div class="betterCategories"><a class="' . $new_style . '" href=\"www.somewhereawayfrombookoasis.com\">';
} else {
    $content .= '<div class="betterCategories"><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
}

good luck!

13 Jan 2016, 3:44 PM
#5
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

I'll try to remember that formatting tip when pasting code, thanks. (Though between you and me, I don't think there's anything that can make it look easier to read. LOL)

Once I changed href="www.timelesserotica.com" to href="http://www.timelesserotica.com" it worked perfectly. THANK YOU SO VERY MUCH!!!!!!!!!!!!!!!!!!!!!

14 Jan 2016, 3:17 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

carlwhat:

DK,
few things; when posting code on the forum, use square brackets with 'php' or 'code' inside of the brakets. and then end the code section again with the square brackets and a slash and the appropriate tag as the ending tag. it makes it much easier to read (and i'm sure there are notes on it somewhere).

Umm yeah. In the posting tips that appear above every new post unless using the mobile template to access this forum site... Basically the 9th bullet or the links in the last paragraph. I thought the terminology was a bit different in the past to include posting code, but perhaps it got modified again like the language section did a while back...

Question about this solution, is it the last two possible categories, a specific set of categories that are to redirect, or simply the last two options displayed in the list?

What happens when/if the categories get deleted, or repurposed? Okay, not really what will happen, but what would be desired to happen? What if a new category is created?

As far as the link as it was provided, it was missing either the (as I've been told) rarely used relational double slash, or the applicable prefix of http:// or https://. The choice taken was to hard code http://. Also could have generated an ez-page that could be referenced in a similar manner but the uri of the ez-page can be modified from within the admin rather than requiring ftp to the file(s) above...

15 Jan 2016, 5:02 AM
#7
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

MC, in this case, it's two specific category listings that just happen to be listed last. I made sure to associate the code changes with the actual category numbers so that if another category was added below (though I wouldn't list it below, as I want those two categories to be listed last), the refresh commands would not be affected.

Thanks again, everyone, for your help; we're very grateful to have solved this puzzle!!

28 Jan 2016, 6:03 AM
#8
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

Okay, I tried the same trick with another site, but it didn't work. Can anyone please help me figure out what I did wrong?

I inserted this block of code (identical to the first except the cPaths and urls are changed):

if ($box_categories_array[$i]['path'] == 'cPath=16') { 
    $content .= '<div class="betterCategories"><a class="' . $new_style . '" href="http://www.book-oasis.com\">'; 
} elseif ($box_categories_array[$i]['path'] == 'cPath=17') { 
    $content .= '<div class="betterCategories"><a class="' . $new_style . '" href="http://www.carnal-pleasures.com\zencart\">'; 

just above:

} else { 
$content .= '<div class="betterCategories"><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
if ($box_categories_array[$i]['current']) {
if ($box_categories_array[$i]['has_sub_cat']) {
$content .= '<span class="category-subs-parent">';
$content .= cat_with_pointer($box_categories_array[$i]['name'], 'down', $spacer);
$content .= '</span>';
} else {
$content .= '<span class="category-subs-selected">';
$content .= cat_with_pointer($box_categories_array[$i]['name'], 'nosub', $spacer);
$content .= '</span>';
}
} else {
if ($box_categories_array[$i]['has_sub_cat']) { 
$content .= cat_with_pointer($box_categories_array[$i]['name'], 'right', $spacer); }
else { 
$content .= cat_with_pointer($box_categories_array[$i]['name'], 'nosub', $spacer); }
}

Am I putting it in the wrong place?

Many thanks, in advance, for your assistance!!

28 Jan 2016, 6:19 AM
#9
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK_Scully:

Is there an easy way to do this?

Heck yes, and far simpler than the suggestions already made.

I'm going to hate myself for this - but the 'easy' solution summed up in one word '.htaccess'.

Something like

Redirect 301 /index.php?main_page=index&cPath=8 http://someothersite.com
Redirect 301 /index.php?main_page=index&cPath=7 http://someothersite.com/something/

Cheers
RodG

28 Jan 2016, 6:26 AM
#10
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

I'll try it! Which copy of .htaccess should I modify? So far the only copy I've found is in the /includes/ folder, and adding:

Redirect 301 /index.php?main_page=index&cPath=16 http://book-oasis.com
Redirect 301 /index.php?main_page=index&cPath=17 http://carnal-pleasures.com/zencart/ 

to the end of it didn't do anything at all.

28 Jan 2016, 7:13 AM
#11
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK_Scully:

I'll try it! Which copy of .htaccess should I modify? So far the only copy I've found is in the /includes/ folder,

EXCELLENT. Well done - I've finally found someone with a ZenCart website working and functioning as designed. :-)

So, to answer your question, you will need to create an .htaccess file and place it in the 'root' folder of your store (this is the same place that you'll find the favicon, robots.txt, ipn_man_handler.php and several other files).

In addition to the two lines already given, since this is a new .htaccess file you will probably need to add the following two lines at the start of the file

Options +FollowSymLinks
RewriteEngine on

The +FollowSymlinks probably isn't required - but most of the code examples I've just looked at seems to have it.

After you have confirmed that the two example redirects work (by typing the one to be redirected into your web browser) you may need to add additional rules for possible variants - This is especially true if your categories are nested - For example if that category '17' is a subcategory of category '1' you will find that both

index.php?main_page=index&cPath=17
and
index.php?main_page=index&cPath=1_17
both load the same page and depending on how the site is navigated either or both can be generated by Zencart - As such, you will need a redirect for both.

Although it is also possible to replace the 'simple redirect' with a 'RedirectMatch' which will enable the use of REGEX like expressions to cater for both variants with a single rule it isn't something I'd recommend at this stage, because it can be too easy to create a REGEX (Regular Expression) that will match things you don't want matched.

Please note, that I'm no expert in the syntax of any of the .htaccess rules. I tend to only use them to allow/deny access (coincidental name or what?) ;-)

In the times I need to know how to write a rule, I use Google to find a generator that crates them for me, then I just do a copy/paste. I even did this to provide you with the two examples already given :)

Anyway, I'm ranting again... start simple... extend as/when needed.

Tip: If you mess up the .htaccess rules (especially syntax errors) you will crash your site (typically a 'Server 500 error'). This is nothing to panic about - simply delete the file (or added rules) and redo.

There is no need to restart the server or clear any caches for changes to the .htaccess file to come into effect - The file is re-read with each and every page request - so its a matter of "stuff ups and fixes while you watch" so it is very easy to test/check that all is working as expected.

Cheers
RodG

28 Jan 2016, 3:11 PM
#12
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

I thought you said this was easier!! LOL

Okay, let me pick my way through it and see if I can figure it out...........

28 Jan 2016, 3:45 PM
#13
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK_Scully:

I thought you said this was easier!! LOL

Okay, let me pick my way through it and see if I can figure it out...........

My apologies, I think I may have made it appear a little overcomplicated this time around.

I'll try again. Using the two category examples that you originally gave you'll need one redirect rule for each, plus the additional line "rewrite engine on" and maybe the "followsymlinks"

Everything beyond that is on an if needed basis.

Cheers
RodG

10 Jun 2017, 9:27 PM
#14
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

We had another site that needed category redirects created, so I tried your .htaccess suggestion. It did...absolutely nothing, to be honest.

I started with the one in /includes/ and removed everything below the ## line, then added in the lines you recommended. The end product is:

#
# @copyright Copyright 2003-2013 Zen Cart Development Team
# @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
# @version GIT: $Id: Author: IronLady  Thu Aug 1 16:10:02 2013 +0100 Modified in v1.5.2 $
#
# This is used with Apache WebServers
#
# The following blocks direct HTTP requests to all filetypes in this directory recursively, except certain approved exceptions
# It also prevents the ability of any scripts to run. No type of script, be it PHP, PERL or whatever, can normally be executed if ExecCGI is disabled.
# Will also prevent people from seeing what is in the dir. and any sub-directories
#
# For this to work, you must include either 'All' or at least: 'Limit' and 'Indexes' parameters to the AllowOverride configuration in your apache/conf/httpd.conf file.
# Additionally, if you want the added protection offered by the OPTIONS directive below, you'll need to add 'Options' to the AllowOverride list, if 'All' is not specified.
# Example:
#<Directory "/usr/local/apache/htdocs">
#  AllowOverride Limit Options Indexes
#</Directory>
###############################


Options +FollowSymLinks
RewriteEngine on

Redirect 301 /index.php?main_page=index&cPath=342 http://www.timelesserotica.com
Redirect 301 /index.php?main_page=index&cPath=343 http://www.book-oasis.com

Obviously I'm missing something. Help, please?

11 Jun 2017, 7:43 AM
#15
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK_Scully:

Obviously I'm missing something. Help, please?


"you will need to create an .htaccess file and place it in the 'root' folder.."

Cheers
RodG

11 Jun 2017, 11:48 AM
#16
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

This is on a shared server with many other websites. I put it in the root folder for that site. I even tried changing the path so it says /zencart/index.php?main_page=index&cPath=343 http://www.book-oasis.com since the zencart program is in a folder. Nothing works.

12 Jun 2017, 9:45 AM
#17
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

DK_Scully:

This is on a shared server with many other websites.

Most are. :)

DK_Scully:

I put it in the root folder for that site.

Correct (I thought I detailed that earlier?)

DK_Scully:

I even tried changing the path so it says /zencart/index.php?main_page=index&cPath=343 http://www.book-oasis.com since the zencart program is in a folder. Nothing works.

This may or may not be right, it really depends of the perspective of the server, and more specifically, the defined document root.

I would suggest that you be smart here, and use the tools available to you. Assuming you have cPanel, and also assuming you know what you want to redirect, and where you wish to redirect, log into the cPanel, find the Redirect tool, then just enter the data. Heck, don't even try typing it. First go the the page you want redirected - copy its URL Now got to where you want to end up. Copy its URL. Now just paste that into the relevant fields and save.

The only difference between this method and the .htaccess method is none. It is the same method. It just that using the cPanel tool ensures that you are editing the right .htaccess file, and also prevents you from making other syntax errors that can occur with manual edits.

Cheers
RodG

13 Jun 2017, 4:30 AM
#18
dk_scully avatar

dk_scully

Zen Follower

Join Date:
Jan 2011
Posts:
339
Plugin Contributions:
0

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

That didn't work, either. I selected the proper website name, and added zencart/index.php?main_page=index&cPath=343 in the second field. It created a redirect, but it didn't take the full url. Instead, it cut it off at https://www.carnal-pleasures.com/zencart/index.php and won't take the remainder. So of course it won't refresh anything. Any other suggestions? Thanks!

13 Jun 2017, 5:08 AM
#19
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

post the url of the site as well as the contents of the .htaccess file.

13 Jun 2017, 6:04 AM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: What's The Easiest Way To Create A Direct Link In The Sidebox?

Might I suggest that until the to/from is correctly applied or identified that you use a 302 instead of a 301? (ie. A temporary move instead of a permanent move?) almost no telling how many different uris/servers have been redirected permanently for a "test".