2

I need to print my "article title" in Joomla intro text article content. I have this code

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    echo $article->get("title");
}

This code work fine after the "read more" button but before it does not work... Somebody can help me? I need to print the title in the intro text.

  • Bit confused by exactly what you need. Articles always show titles in blog or category list format unless you specifically set the article options to hide the title. You can have different settings in the article and category display. From what you are describing you just have titles set to hide on the category view – MOLEDesign Jul 17 '14 at 16:51
  • I have a reservation form, and I need to send via url the name of the article... <a href="hotels/book-hotel?hotel=<?php article name ?>">Book NOW</a> – Csar Otárola Jul 17 '14 at 17:11
  • Ah right, you just need to use the title variable in the category list/blog view as opposed to the article view. – MOLEDesign Jul 17 '14 at 17:29
  • I have not the slightest idea how to do that. – Csar Otárola Jul 17 '14 at 19:34
  • Your starting point is to add a second if statement similar but starting with if ($option=="com_content" && $view=="category") { You then just have to find a way to pull in the article title from the BLOG / LISt view. So you will have two similar chunks of code, one that only fires on the SINGLE article view and one that fires on the BLOG type view. I will try to have a look tomorrow. Personally I would just write an override in the default article template to generate this link as opposed to doing it in each individual article – MOLEDesign Jul 17 '14 at 23:10
4

If you have selected category blog view and you need to print the article just after the intro text, try to override the following template: /templates/yourtemplate/html/com_conetnt/category/blog_item.php

And paste in this:

    $option = JRequest::getCmd('option');
    $view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="category") {
    echo $this->item->title;
   }

right after :

$this->item->introtext;
  • Template override definitely the way to go – MOLEDesign Jul 19 '14 at 0:20
  • This works ... but it would work even better if I could print it within the content of the article intro text joomla, not a position of the template. – Csar Otárola Jul 22 '14 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.