Previous And Next Product Mod W/ SEO Links

first, in addons/seo/func.php



search for:


if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\{\$product.product_id\})([&|&]?)/i', $tpl_source, $matches)) {
foreach ($matches[0] as $key => $match) {
$tpl_source = str_replace($match, '{"p"|fn_seo_link:$product.product_id:$product.product}' . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);
}
}




insert after:



if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\{\$previous.product_id\})([&|&]?)/i', $tpl_source, $matches)) {
foreach ($matches[0] as $key => $match) {
$tpl_source = str_replace($match, '{"p"|fn_seo_link:$previous.product_id:$previous.product}' . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);
}
}

if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\{\$next.product_id\})([&|&]?)/i', $tpl_source, $matches)) {
foreach ($matches[0] as $key => $match) {
$tpl_source = str_replace($match, '{"p"|fn_seo_link:$next.product_id:$next.product}' . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);
}
}




save and exit



next in includes/customer/products.php



search for:


if (!empty($product['meta_description']) || !empty($product['meta_keywords'])) {




insert before:



$next_id=0;
$prev_id=0;
$q = "select product_id from $db_tables[products_categories] where category_id=$product[main_category] and link_type='M'";
$test = db_get_hash_array($q,'product_id');
sort($test);
for ($i=0;$i $last = count($test)-1;
if ($test[$i]['product_id'] == $product_id) {
if ($i==0) $prev_id = $test[$last]['product_id'];
else $prev_id = $test[$i-1]['product_id'];
if ($i == $last) $next_id = $test[0]['product_id'];
else $next_id = $test[$i+1]['product_id'];
$i = $last;
}
}
$next = fn_get_product_data($next_id, $auth, $cart_language);
$previous = fn_get_product_data($prev_id, $auth, $cart_language);
$smarty->assign('next', $next);
$smarty->assign('previous', $previous);




save and exit



lastly, in skins//customer/products_pages/product_details.tpl



enter something like:


```php







{if ($previous.product_id!=0 && $previous.product_id!='')}
« Previous
{/if}

{if ($next.product_id!=0 && $next.product_id!='')}
Next »
{/if}


```

wherever you would like the prev/next links to appear (top, bottom, top and bottom, etc...)

save, exit and enjoy

note: if you used the version of the mod I posted in another thread, this is an updated version of that, and some code has changed so that it works with the SEO functionality of cscart's seo addon

Hello luckdragon,



Thank you so much!





You’re the best!







Lee Li Pop

Hello LuckDragon,



In addons/seo/func.php



Change this:


if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\{\$previous.<br />
product_id\})([&|&]?)/i', $tpl_source, $matches)) {<br />
                foreach ($matches[0] as $key => $match) {<br />
                        $tpl_source = str_replace($match, '{"p"|fn_seo_link:$previous.product_id:$previous.<br />
product}' . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);<br />
                }             <br />
        }
```<br />
<br />
With this:<br />
<br />
```php
if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\{\$previous.product_id\})([&|&]?)/i', $tpl_source, $matches)) {<br />
                foreach ($matches[0] as $key => $match) {<br />
                        $tpl_source = str_replace($match, '{"p"|fn_seo_link:$previous.product_id:$previous.product}' . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);<br />
                }             <br />
        }
```<br />
<br />
Why?<br />
<br />
Because your code is on two lines:<br />
<br />
```php
product_id=\{\$previous.<br />
product_id\}
```<br />
<br />
And<br />
<br />
```php
{"p"|fn_seo_link:$previous.product_id:$previous.<br />
product}
```<br />
<br />
To works, this code MUST be on ONE line!<br />
<br />
Remember!<br />
<br />
[B]AFTER moding[/B]:<br />
<br />
[B]Administration > Cleanup templates cache[/B]!!!<br />
<br />
VERY  BEAUTIFUL  MOD!<br />
<br />
![](upload://ztuXVbvZ3u7WtDNkXtUem4JK5e3.jpeg)<br />
<br />
Evrything is explain there:<br />
<br />
[url]http://forum.cs-cart.com/showpost.php?p=40813&postcount=16[/url]<br />
<br />
<br />
<br />
Lee Li Pop

Hello LuckDragon,



More SEO Tip:



[SIZE=“3”]Add Product Name in Anchor Text![/SIZE]



in skins//customer/products_pages/product_details.tp



Change this:


« Previous



With this:


« {$previous.product}



AND



Change this:


Next »



With this:


{$next.product} »







Lee Li Pop



PS: Your Mod is Fantastic!

thank you for the 1 line correction… thought I caught them all when I pasted it…



I’m going to be creating a script (kind of like matt’s) to “house” my free scripts for people to get them directly from my site which will help alleviate that in the future.



:slight_smile:

Thank you Luckdragon for this mod. The mod works great and I even figured out how to change the previous and next text to an image so it looks really great now.



I tried to figure this out myself, but apparently I’m not smart enough, but is there anyway to do this for the admin side. Sometimes I need to edit my products and it would be nice to just click “next” instead of opening up each product in a new tab or having to click the browser’s back button.



Thank you again,



Brandon

hi brandon… that’s a pretty good idea… I’ll see what i can come up with :slight_smile:

[quote name=‘luckdragon’]thank you for the 1 line correction… thought I caught them all when I pasted it…



I’m going to be creating a script (kind of like matt’s) to “house” my free scripts for people to get them directly from my site which will help alleviate that in the future.



:)[/QUOTE]



Did you post your mods online? It would be good for the community.

[quote name=‘clips’]Did you post your mods online? It would be good for the community.[/QUOTE]

Just follow the above instructions then you will be fine…

[quote name=‘joe’]Just follow the above instructions then you will be fine…[/QUOTE]



Yeah, I thought about that, but I’m doing good to make changes when they just give one option or set of directions. If I have to go through corrections or add tags, or whatever I’m sure to mess something up.

Hi!



I added this mod to my site www.electrogeneral.com however it is not working properly.



May it be because I changed the words “next” and “previous” to spanish: “siguiente” and “anterior”? do i need to create a language variable for this mod? :roll:



Just in case I explain here what I did. I made all the modifications suggested by luckdragon, then I changed it to what Lee li pop said, but the last Lee li pop seo tip I realized it didn’t look well in my store since I have products with very long names so I kept it like luckdragon had it but changed the english words for the spanish equivalents, like this:








{if ($previous.product_id!=0 && $previous.product_id!='')}
« Anterior
{/if}

{if ($next.product_id!=0 && $next.product_id!='')}
Siguiente »
{/if}



Now, if you go to my page and click on Tv & Video, then on Televisores LCD, you'll see a long long list of TV, click on the 1st and try to advance from there thru the links next and previous.

And while I'm here, can anyone help me change the pagination in product lists. I wish I had also there "next" and "previous" and maybe 3/14 in between, not the intervals I have right now.

English is not my mother tongue and it is very late at night over here, I'm falling asleep right now, so forgive me I do not express the idea correctly. If I need to explain myself again, go ahead and ask;)

Thanks in advance!

Hello Mirnitagl,


[quote name=‘mirnitagl’]

Just in case I explain here what I did. I made all the modifications suggested by luckdragon, then I changed it to what Lee li pop said, but the last Lee li pop seo tip I realized it didn’t look well in my store since I have products with very long names so I kept it like luckdragon had it but changed the english words for the spanish equivalents, like this:[/QUOTE]



Lee Li Pop ask you:



Do you know CSS (hojas de estilo en cascada)?



Use it!







Lee Li Pop

no, I do not know css, if I knew how to solve it I wouldn’t have asked.



Anyway, thank you for your help.

Hello Mirnitagl,



1 - Try this:


```php






{if ($previous.product_id!=0 && $previous.product_id!='')}{$previous.product}{/if} {if ($next.product_id!=0 && $next.product_id!='')}{$next.product}{/if}
```

2 - Put the links pictures (Attached Images, see below) in your [COLOR="Blue"]/skins/[COLOR="Red"][your skin][/COLOR]/customer/images[/COLOR] directory

2 - Put this links table below your product's picture, like in this website:

[url]http://www.afashion.net/silver-cross-necklace-p-485.html[/url]

Why?

Because everybody click on it!

Why everybody click on it?

Because it's like [URL="http://www.windowsvistauserguide.com/windows_photo_gallery.htm"]Windows Photo Gallery[/URL]!

aFashion.net is [COLOR="Red"]NOT[/COLOR] my website!

Viva el Rey CSS !



Lee Li Pop

next.png

previous.png

all.png

Nice mod!



I note that it requires code in “addons/seo/func.php”



I run 1.3.5 SP3. func.php does not exist in that folder. In that case, where do I put the first part of the code?



Thanks,

Greg

Hi, Lee Li Pop!



Thank you for taking the time of seeing this for me.

I did as you advised though I didn’t place the arrows under the picture, but at the beginning of mainbox. I think placing the arrows under the item picture may be confusing for the customer as he might think it is to show more images of the same product.

This change was a great improvement since now the option is quite visible, not like the next and previous small letters I had before.



Having said that I realize I continue with the same problem I had when I posted here. I was not able to express myself well before so I’ll try to do it better now.



When you go to any item in my site www.electrogeneral.com, the next and previous arrows work only if the next item is the same product but with a different code, for example “TV 37” Sony really cute" then the next item is “TV 37” Sony really cute+ 2 cables", then the next product is “TV 37” Sony really cute+ 2 cables+ 2 cleaning wipes boxes"

Like that the arrows work, but when it gets to “TV 42” Samsung awfylly cute" it stops there, even if there are 1000 more tvs to be seen in the list.



And if you go directly to a product whose next item is different, not related as explained before, then the arrows dissapear.

For example:

[url]http://www.electrogeneral.com/tv-video/televisores/pantalla-plasma.html[/url]

This is the category TV and video, subcategory “televisores”, subcategory “pantalla plasma”

As you can see the list is very long, ok, now click on the 1st item, which is this:

[url]http://www.electrogeneral.com/pantalla-de-plasma-50pfp5532-50-pulgadas-127-cm-16-9-hd-ready-tdt-hdmi-x2.html[/url]

where did the arrows go???:confused: It is springtime so they went on a picnic:D



This is weird, isn’t it? I swear I followed luckdragon’s instructions step by step. I may know nothing about coding but I’m a pro at copying and pasting :cool:



Any ideas of why this might be happening? Lee Li Pop, the images do look really cute and match perfectly my store colors, thanks.



I imagined the example site was not yours, the truth is I’d love to see your site. I have read some of your comments in this forum for the past months, liked your mods. You are good at coding and a seo expert, your site must be “a sight to see”



Viva este foro!!!

Hello Mirnitagl,



It’s NOT my mod!



[SIZE=“3”][COLOR=“Blue”]This Mod is made by Luckdragon![/COLOR][/SIZE]



Luckdragon is one of the best freelance programmers of CS-Cart community!



1 - Edit product_details.tpl:



[COLOR=“Blue”]/skins/[COLOR=“Red”][your skin][/COLOR]/customer/products_pages/[COLOR=“Red”]product_details.tpl[/COLOR][/COLOR]



Insert the navigation table just below the product’s picture. Find code:



{include file="common_templates/image.tpl" show_detailed_link="Y" obj_id=$product.product_id images=$product.main_pair object_type="product"}




Add this code after (below):


```php






{if ($previous.product_id!=0 && $previous.product_id!='')}{$previous.product}{/if} {if ($next.product_id!=0 && $next.product_id!='')}{$next.product}{/if}
```

2 - Try these 2 files:

[COLOR="Blue"]/include/customer/[COLOR="#ff0000"]products.php[/COLOR][/COLOR]

[COLOR="Blue"]/addons/seo/[COLOR="Red"]func.php[/COLOR][/COLOR]

@ ustomfx,

All paths here are from [COLOR="Red"]ROOT[/COLOR] directory.



Lee Li Pop

products.zip

func.zip

Ahhh thanks Lee Li Pop :slight_smile:



I know my around fairly well, but didnt even think of looking in the Root. I was looking under skins…



Thanks. :slight_smile:

Hi Lee Li Pop,



I now have it working just fine.



Question. The middle button:


[QUOTE][/QUOTE]



How can this be linked to the next level up in the breadcrumb (ie the parent category)?



Many thanks for your help :slight_smile:



Greg

Hi, Lee li pop!



I never said THIS was your mod, I know it is luckdragon’s and I agree that he is one of the best coders in this community.



Please, read my previous message again, if i say that i have been following your comments and liked your mods, I do not refer specifically to this one. you have also given seo indications in this forum , have made seo mods and have participated in so many other threads.



I never meant to take luckdragon’s credit away for this mod whatsoever!



However I believe your arrows addition improves it.



Now I will follow your last indications and keep my fingers crossed.:wink:



Thank you luckdragon and Lee li pop for all the help you’ve given in this and other threads.