Jump to content

Acquiring seo url for kb article on homepage...


Nullified

Recommended Posts

$articles = array();
$result = mysql_query("SELECT id, title, article, views, useful FROM tblknowledgebase ORDER BY useful DESC LIMIT 5");
while ($data = mysql_fetch_array($result)) {
$data['urlfriendlytitle'] = str_replace(' ', '-', $data['title']);
array_push($articles, $data);
}
$this->_tpl_vars['articles'] = $articles;

 

The code works fine, but the line I am concerned about is $data['urlfriendlytitle'] = str_replace(' ', '-', $data['title']);

 

Did I code it correctly so it will work or will i risk some problems with articles that have characters in the title that may need to be escaped? I don't know where or how WHMCS pulls {$article.urlfriendlytitle} from as it's not in the database table so I developed my own code.

Link to comment
Share on other sites

Update: What I need is the same function that WHMCS developers use so I can duplicate it on the homepage.

 

I changed the mysql query to and it seems to be working:

$result = mysql_query("SELECT id, title, article, views, useful, replace(replace(replace(replace(replace(replace(replace(title,' ','-'),'&','and'),'&','and'),',',''),';',''),'/','or'),'\\\\','') as urlfriendlytitle FROM tblknowledgebase ORDER BY views DESC LIMIT 5");

Edited by Nullified
Link to comment
Share on other sites

UPDATE: I got the code to acquire the category name for better seo, however I am having some htaccess rewriterule issues.

 

If you would like to help please see this thread.

 

{foreach key=num item=article from=$viewed}
{php}
$category = array();
$result = mysql_query("SELECT categoryid AS id FROM tblknowledgebaselinks WHERE articleid = '" . $this->_tpl_vars['article']['id'] ."'");
while ($cats = mysql_fetch_assoc($result)) {
$category['id'] = $cats['id'];
$result = mysql_query("SELECT name, replace(replace(replace(replace(replace(replace(replace(name,' ','-'),'&','and'),'&','and'),',',''),';',''),'/','or'),'\\\\','') as urlfriendlytitle FROM tblknowledgebasecats WHERE id = '" . $cats['id'] ."'");
while ($cats = mysql_fetch_assoc($result)) {$category['urlfriendlytitle'] = $cats['urlfriendlytitle'];}
}
$this->_tpl_vars['category'] = $category;
{/php}
<div align="left" class="kbarticle"><img src="images/article.gif" align="middle" alt="" border="0" /> <strong><a href="{if $seofriendlyurls}knowledgebase/{$article.id}/{$category.urlfriendlytitle|strtolower}/{$article.urlfriendlytitle|strtolower}.php?article={$article.id}{else}knowledgebase.php?action=displayarticle&id={$article.id}{/if}">{$article.title}</a></strong><span class="kbviews">{$LANG.knowledgebaseviews}: {$article.views}</span></div>
{/foreach}

Edited by Nullified
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated