This mod upgrades the simplistic article rewrite from phpLD 3.3. After installing this mod your article URLs will turn from http://www.mydirectory.com/articles/article-239.html to http://www.mydirectory.com/articles/your-article-title-here.html
Important: backup all files before modifying them!

  1. Open admin/article_edit.php
    Find
    if ($action == 'N')
    {
    $data['DATE_ADDED']    = gmdate ('Y-m-d H:i:s');
    }
    
    Replace with
    if ($action == 'N')
    {
    $data['DATE_ADDED']    = gmdate ('Y-m-d H:i:s');
    $data['TITLE_REWRITE'] = preg_replace ('`[^\w_-]+`', '-', $data['TITLE']);
    }
    
  2. Open submit_article.php
    Find
    $data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
    
    Replace with
    $data['META_KEYWORDS'] = (!empty ($data['META_KEYWORDS']) ? clean_meta_keywords($data['META_KEYWORDS']) : '');
    $data['TITLE_REWRITE'] = preg_replace ('`[^\w_-]+`', '-', $data['TITLE']);
    
  3. Open include/tables.php
    Find
    $tables['article'] = array (
    'name'   => TABLE_PREFIX.'ARTICLE'               ,
    'fields' => array (
    'ID'                 => 'I KEY AUTO'          ,
    'TITLE'              => 'C(255) NOTNULL'      ,
    
    Replace with
    $tables['article'] = array (
    'name'   => TABLE_PREFIX.'ARTICLE'               ,
    'fields' => array (
    'ID'                 => 'I KEY AUTO'          ,
    'TITLE'              => 'C(255) NOTNULL'      ,
    'TITLE_REWRITE'      => 'C(255) NOTNULL'      ,
    
    Find
    $tables['article_review'] = array (
    'name'   => TABLE_PREFIX.'ARTICLE_REVIEW'               ,
    'fields' => array (
    'ID'                 => 'I KEY AUTO'          ,
    'TITLE'              => 'C(255) NOTNULL'      ,
    
    Replace with
    $tables['article_review'] = array (
    'name'   => TABLE_PREFIX.'ARTICLE_REVIEW'               ,
    'fields' => array (
    'ID'                 => 'I KEY AUTO'          ,
    'TITLE'              => 'C(255) NOTNULL'      ,
    'TITLE_REWRITE'      => 'C(255) NOTNULL'      ,
    
  4. Open index.php
    Find
    //Article search
    $search_preferences = array ();
    $search_preferences['Select_Options']  = array ( '`ID`'                      ,
    '`TITLE`'                ,
    
    Replace with
    //Article search
    $search_preferences = array ();
    $search_preferences['Select_Options']  = array ( '`ID`'                      ,
    '`TITLE`'                ,
    '`TITLE_REWRITE`'        ,
    
  5. Open search.php
    Find
    //Add search query
    $search_preferences['search'] = $searchPrefs['query'];
    $search_preferences['Select_Options']  = array (   '`ID`'                      ,
    '`TITLE`'                   ,
    
    Replace with
    //Add search query
    $search_preferences['search'] = $searchPrefs['query'];
    $search_preferences['Select_Options']  = array (   '`ID`'                      ,
    '`TITLE`'                   ,
    '`TITLE_REWRITE`'        ,
    
  6. Open .htaccess
    Find
    RewriteRule (.*)articles/article-(.*)\.htm[l]?$ article.php [QSA,NC]
    
    Replace with
    RewriteRule (.*)articles/(.*)\.htm[l]?$ article.php [QSA,NC]
    
  7. Open article.php
    Find (around line 158)
    elseif (ENABLE_REWRITE == 1)
    {
    preg_match ('#(.*)article(_|-)(\d+)\.htm[l]?$#i', request_uri(), $matches);
    $id = (!empty ($matches[3]) ? intval ($matches[3]) : 0);
    }
    
    Replace with
    elseif (ENABLE_REWRITE == 1)
    {
    preg_match ('`articles/([\w_-]+)\.htm[l]?$`', request_uri(), $matches);
    $rdata = $db->GetRow("SELECT `ID` FROM `{$tables['article']['name']}` WHERE `TITLE_REWRITE` = '$matches[1]'");
    if (!$rdata)
    {
    $tpl->assign('error', "Invalid article title - not found in database");
    $id = 0;
    }
    else
    {
    $id = $rdata['ID'];
    }
    }
    
  8. Now you have to edit the template files that reference articles. The general rule is to replace anything that references
    articles/article-{$article.ID}.html
    with
    articles/{$article.TITLE_REWRITE}.html

    NOTE: $article is just a random name. It could appear as $val, $latest_search[i] etc depending on your template. You have to replace it keeping the same variable name (i.e. $val.TITLE_REWRITE, $latest_search[i].TITLE_REWRITE)

    For example, for the Professional template (the default that comes with 3.3) you have to make the replacements in
    • templates/Professional/articlelink.tpl
    • templates/Professional/article_search.tpl
    • templates/Professional/rightside.tpl
    • templates/Professional/rss2.tpl
  9. Run these SQL queries from the phpLD admin System->Database page or from phpMyAdmin
    ALTER TABLE `PLD_ARTICLE` ADD `TITLE_REWRITE` VARCHAR( 255 ) NOT NULL AFTER `TITLE`
    ALTER TABLE `PLD_ARTICLE_REVIEW` ADD `TITLE_REWRITE` VARCHAR( 255 ) NOT NULL AFTER `TITLE`
    UPDATE `PLD_ARTICLE` SET `TITLE_REWRITE`=CONCAT('article-', `ID`)
    UPDATE `PLD_ARTICLE_REVIEW` SET `TITLE_REWRITE`=CONCAT('article-', `ID`)
    

Official help on our support forum

Back to the Mods collection