Permalinks url question

By Jesus - August 29, 2014

Hi,

I'm wondering if its possible to have a different url (filling the permalink field) while selecting a category from a select box.

Example:

I've a select box with 3 categories: News, Info and Articles

and I want to have my permalink to be something like:

/blog/news/article-name if News category was selected

/blog/info/article-name if Info category was selected

/blog/articles/article-name if Articles category was selected

Thanks in advance!

By Jesus - August 29, 2014

Great Daryl!

One more thing... what if I'm also using the permalinks on another sections?

Will try to explain it better... this example was for the blog and I understood perfectly what it needs to be done; but lets say I also have a couple more sections in my CMSBuilder admin (products and services). On this 2 sections, I don't use the categories (or even a category field) on it.

Will you please clarify this a little for me? (if possible :) )

Thanks!

By Daryl - August 29, 2014

That's a good question.

If you want to implement this to a particular section, then we need to add an if block to check for the tablename. For example:

if ($tableName == "blog"){
    $requiredPrefix .= "blog/" . @$_REQUEST['category'] . "/";
}

Please let me know if that works for you.

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com

By Jesus - August 29, 2014

AWESOME! Will give this a try!

Thanks a lot!

By Jesus - September 16, 2014 - edited: September 16, 2014

Hi Daryl,

Here's the code I'm trying, with no luck yet. Am I missing something:

  if ($tableName == "cms_blog"){
     $requiredPrefix .= "blog/" . @$_REQUEST['categoria'] . "/";}

Should I keep or not the cms_ prefix on the table name?

Hi Jesus, 

You don't need to include the table prefix, you can just use the section name instead:

if ($tableName == "blog"){
   $requiredPrefix .= "blog/" . @$_REQUEST['categoria'] . "/";}

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Jesus - October 4, 2014

Hi folks,

Still no luck wile trying to implement this one. Here's the code I'm using:

  // is autopopulate needed?
  $permalinkText  = @$_REQUEST['permalink'];
  $requiredPrefix = $GLOBALS['schema']['permalink']['defaultValue'];
  if ($tableName == "blog"){
    $requiredPrefix .= "blog/" . htmlspecialchars(@$_REQUEST['categoria']) . "/";
  }
  $doAutopopulate = ($permalinkText == '' || $permalinkText == $requiredPrefix);
  if (!$doAutopopulate) { return; }

I tried both options:

$requiredPrefix .= "blog/" . @$_REQUEST['categoria'] . "/";}

and

$requiredPrefix .= "blog/" . htmlspecialchars(@$_REQUEST['categoria']) . "/";

Hi Jesus,

I've found a much easier way to do this. At the top of the plugin is a line where you can set what fields are used to create the permalink, if you add the item menu to it, the section name will be added to the permalink field:

$GLOBALS['PERMALINKS']['autopopulate_fromFields'] = array('name', 'menu title'); 

By doing this you won't need to make any other changes to the plugin, the only downside is that dashes will be used to separate the permalink variables instead of the forward slashes. 

The menu variable is a hidden field that is used by the CMS to store the current section that is being edited. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By zaba - October 8, 2014

is this not a case of the old classic typo? categoria, should be category (based on your previous post)

     $requiredPrefix .= "blog/" . @$_REQUEST['categoria'] . "/";}