[Solved] SEO friendly URL for category

11 posts by 3 authors in: Forums > CMS Builder
Last Post: November 24, 2009   (RSS)

By gcod - November 15, 2009 - edited: November 24, 2009

Hi,

First thanks for this great tool.
I managed to do pretty much everything I wanted to except to change the url for the category list link.

Here is what I have:

A page with a category list that goes to an other page that has the detail of it.

The url of the page with the list in it is /french-polynesia.php

The url of the detail page is /french-polynesia-details.php

My first item in the list is news. The link generated is /french-polynesia-details.php?News-1

What I would like to have is /french-polynesia/news/ as the link.

I can work out some rules in modrewrite to point to /french-polynesia-details.php?News but if I can't change the link in the list it's pointless.

To summary:

I'd like to change the link in the category list to a folder structure with the name of the page that has the list (that can be hard coded) and the name of the item in the category without the number:

/list-page-name/category-item-name/

instead of

/detail-page.php?category-item-name-X

Let me know if I'm not clear enough.

Thanks!
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] SEO friendly URL for category

By Dave - November 16, 2009

Hi gcod, welcome to the CMS Builder forum! :)

There's a number of ways to do custom links that are different from the ones CMSB generates. They all involve a bit of custom work with PHP, MySQL or mod_rewrite (as you suggested).

If you are able to get mod_rewrite to redirect /french-polynesia/news/ to /french-polynesia-details.php?News-1 and all you need is for the link in the list to be different then what about just adding a field for "customLink" and hard coding the link you want to use (since you'll be hard coding it for mod_rewrite as well). Then just output customLink instead of _link.

That's one way, another way is to create a unique field for 'id' or 'tag' where you enter some unique text you can use to lookup the article. Currently we're using the record num to lookup the article. If you had a field called tag you could do this:

/french-polynesia-details.php?tag=vacation

And then use mod_rewrite to redirect /french-polynesia/anything to /french-polynesia-details.php?tag=anything

Let me know if either of those ideas will work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [gcod] SEO friendly URL for category

By Dave - November 17, 2009

You can actually use the build in search features described here:
http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Just remove or comment out this option in your detail viewer:
'where' => whereRecordNumberInUrl(1),

And then create a field called 'tag' if you haven't already done so. Make it unique in the field editor and fill out some values for the different records. Then display a specific record by tag like this:
french-polynesia-details.php?tag=News

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] SEO friendly URL for category

By gcod - November 17, 2009

Thanks Dave,

The link works (/french-polynesia-details.php?tag=vacation instead of /french-polynesia-details.php?vacation-1).

The page targeted display the content of the item clicked but now my list, who act like a sub menu on the detail page, only display the clicked item and not all of them.

Is there a way to fix this?
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] SEO friendly URL for category

By Dave - November 18, 2009

Hi gcod,

Hmm, I'm not exactly sure what you mean. Can you provide an example url and/or attach the viewer file to this thread so I can see your code?

Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] SEO friendly URL for category

By gcod - November 18, 2009

Well,

I've one page with the code for the category list (let's call the detail page of this category list 'sub') and a single page (let's call it 'main'):

Code in the detail 'main' page
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/cmsAdmin/lib/viewer_functions.php";

list($what_is_a_private_islandRecords, $what_is_a_private_islandMetaData) = getRecords(array(
'tableName' => 'what_is_a_private_island',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$what_is_a_private_islandRecord = @$what_is_a_private_islandRecords[0]; // get first record

if (!$what_is_a_private_islandRecord) {
print "Record not found!";
exit;
}

?>

<?php
list($wiapiRecords, $wiapiMetaData) = getRecords(array(
'tableName' => 'wiapi',
));
?>


On this one I display the 'sub' list that act like a menu.
The first item being hardcoded, it's the link to the page you are in right now.

This menu has links for each item of a category (same thing in the 'sub' page):

<ul id="submenu">
<!-- hard coded start -->
<li class="active"><a href="/what-is-a-private-island.php" title="View what is a Private Island">What is a Private Island</a></li>
<!-- hard coded end -->
<?php foreach ($wiapiRecords as $record): ?>
<li><a href="private-island-details.php?customlink=<?php echo $record['customlink'] ?>" title="<?php echo $record['name'] ?>"><?php echo $record['name'] ?></a></li>
<?php endforeach; ?>
</ul>


When you click on an item (private-island-details.php?customlink=FAQ for exemple) you end up in the 'sub' detail page: that contain the detail of every item in the list (one per link).

Here is what I have at the beginning of the code in the 'sub' page:
<?php
require_once "/cmsAdmin/lib/viewer_functions.php";

list($wiapiRecords, $wiapiMetaData) = getRecords(array(
'tableName' => 'wiapi',
//'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$wiapiRecord = @$wiapiRecords[0]; // get first record

// show error message if no matching record is found
if (!$wiapiRecord) {
print "Record not found!";
exit;
}

?>

<?php
list($wiapiRecords, $wiapiMetaData) = getRecords(array(
'tableName' => 'wiapi',
));
?>


The first piece is the detail code for the category page and the second would be the one for the list (who act like a menu, like on the 'main' page).
As you can see here I commented the 'where' like you told me.

The problem is when you click on a link that has the custom link (on the 'main' or in the 'sub') the page you end up is good (it's the 'sub' with the detail of the item clicked) but the menu display only the item clicked and not every one of the them (probably because it act as a search result and only display the item requested).

Do you have an idea how to make this works and display every item not just the one clicked?
If it's not enough to understand let me know I'll attached the file tomorrow.

Thanks.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] SEO friendly URL for category

By gcod - November 20, 2009

Perhaps you've got an other solution, I'm all ears [:)]
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] SEO friendly URL for category

By Chris - November 24, 2009 - edited: November 24, 2009

Hi gcod,

I suspect you probably need to add the following line (in red) to your sub page:

<?php
list($wiapiRecords, $wiapiMetaData) = getRecords(array(
'tableName' => 'wiapi',
'allowSearch' => false,
));
?>


I hope this helps! If not, please attach the complete PHP source code of your sub page. Please let us know if you have any questions.
All the best,
Chris

Re: [chris] SEO friendly URL for category

By gcod - November 24, 2009

It works Awesome!

I'll have the perfect SEO url I wanted.

Thanks Chris and Dave. You rock guys!
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com