How to Migrate Joomla Articles’ Subtitles to K2

We have mentioned before that we are migrating a lot of websites from using Joomla’s core content to K2 because K2 is simply better (well, this is our opinion anyway). But, even though K2 provides all the tools to make the content migration an easy task, quite often, there are quirks here and there that need to be addressed manually to ensure a successful migration.

One of these quirks is that K2 articles, unlike Joomla articles, do not have the concept of a subtitle built-in. Of course, you might be thinking: “What, when did Joomla articles have any subtitle?” Technically, they didn’t – but there are some extensions that make good use of the unused title_alias field in the #__content table and treat it as a subtitle. The title_alias field was not used by Joomla’s core as of Joomla 1.5 (it is deprecated in Joomla 3.0).

Now going back to K2, its automatic migration of Joomla articles to K2 articles does not take into account the unused title_alias – additionally, K2 articles do not have subtitles. Thankfully, with itoctopus, there’s a simple solution to everything (well, nearly everything), so we devised a three-step process to circumvent this limitation:

  1. Step 1: Create an extra field called Subtitle

    Creating an extra field in K2 is extremely simple – and it can be done by just going to K2 -> Extra Fields, clicking on New on the top right, and then filling in the appropriate fields. It’s that simple!

  2. Step 2: Run the subtitle-migration script post article-migration

    The following migration script must be temporarily added to your index.php (on your website) in order to populate K2 articles with subtitles (we are assuming that you only have one extra field; the one that was created above):

    $db = &JFactory::getDbo();
    $sql = "SELECT title, title_alias FROM #__content WHERE title_alias <> ''";
    $row = $db->loadAssocList();
    for ($i = 0; $i < count($row); $i++){
    	$sql = "SELECT id FROM #__k2_items WHERE title='".$row[$i]['title']."'";
    	$id = $db->loadResult();
    	$subtitle = '[{"id":"1","value":"'.$row[$i]['title_alias'].'"}]';
    	$sql = "UPDATE #__k2_items SET extra_fields ='".$subtitle."' WHERE id='".$id."'";

  3. Step 3: Modify your template to use K2’s subtitle

    Open the item.php file which is located under the components/com_k2/templates/[your_k2_template_name] directory and add the following script where you want to display the subtitle field:

    foreach ($this->item->extra_fields as $key=>$extraField){
    	if ($extraField->name == 'Subtitle')

That’s it!

Of course, if you’re not a programmer, then you might believe (and rightly so) that the above is a bit intimidating, and that’s why we exist! Just contact us and we’ll do the subtitle migration for you in the glimpse of an eye (it might take a bit more, but you get the point). And don’t you worry about our fees, they’re very, very affordable!

No comments yet.

Leave a comment