Facebook Login
September 30, 2011

Add Category to your K2 Articles

One good way to increase your seo and ease navigation is to get more info into your 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 results, just look above... If you'd like to see the process, just look below...

Navigate to: com_k2 -> views --> item

Open your view.html.php file

Then search for this code:
//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 . ' | ' . 'YOURSITENAME.com');
For example, my final code ends up looking like this...
//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'));
and looks like this... mytitle
Of course you can do some more tweaking, but I like to keep things as "White-Hat" as possible. If this was useful, toss me some social love!

facebookmetweetme

Other Articles

20 Free and Sexy Wordpress Themes
Our 20 absolute favorite Free Wordpress themes, only a click away.

Read More