Categorize K2 Articles on Joomla!

One good way to increase your seo and ease navigation is to fit a little more info into your Joomla! page title.

If you're using K2 and Joomla here is an easy way to include your category and the name of your website into your page title. If you'd like to see the process, just take a quick look at the brief tutorial below.

Customizing Your K2 Item View

First navigate to your item view, located at com_k2 -> views --> item. Open your view.html.php file. Search for the code below so we can adjust that.

//Set page title
$menus = &JSite::getMenu();
$menu = $menus->getActive();
if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'item' && isset($menu->query['id']) && $menu->query['id'] == $item->id) {
   $menu_params = new JParameter($menu->params);
   if (!$menu_params->get('page_title')) {
      $params->set('page_title', $item->cleanTitle);
   }
} else {
   $params->set('page_title', $item->cleanTitle);
}
$document->setTitle($params->get('page_title'));

Where you see "cleanTitle", you'll want to add a "|" Then the category name another "|" Then your domain name. You do that with the following code cleanTitle . ' | ' . $item->category->name . ' | ' . 'YOURSITE.com'). For this example, your final code block will end up looking like the block below.

//Set page title
$menus = &JSite::getMenu();
$menu = $menus->getActive();
if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'item' && isset($menu->query['id']) && $menu->query['id'] == $item->id) {
   $menu_params = new JParameter($menu->params);
      if (!$menu_params->get('page_title')) {
         $params->set('page_title', $item->cleanTitle . ' | ' . $item->category->name . ' | ' . 'HaeckDesign.com');
   }
} else {
   $params->set('page_title', $item->cleanTitle . ' | ' . $item->category->name . ' | ' . 'HaeckDesign.com');
}
$document->setTitle($params->get('page_title'));

Your Final Customized Joomla Title

Using the code above will append your category title to the end of your usual page title. The final result will provide a little more useful info and seo content. Your page title will end up looking like this...

Joomla K2 Title - Screenshot

Of course you can do more tweaking for whatever your specific project requires. K2 does offer a lot of firepower to Joomla users and hopefully this addition adds a little more impact to your seo. We hope you've found this brief tutorial helpful and if you have, please be sure to share online with any of the buttons below.

  • Published:
  • Author:
  • Category: tutorial
  • Share:
  • Title: Categorize K2 Articles on Joomla!
  • Summary: One solid way to boost your SEO and ease navigation is to add K2 categories into your Joomla! page title.
Signup for Linode & Get $100 Credit Donate A Coffee
Latest Design & Development News
If you love web development, graphic design, or tech tools, be sure to visit our blog for tons of helpful info.