【问题标题】:Joomla 3: adding category-image in article templateJoomla 3:在文章模板中添加类别图像
【发布时间】:2014-12-23 20:33:14
【问题描述】:

我正在覆盖我的 Joomla 3 网站的文章模板 default.php。我需要将类别图像添加到我的文章模板中。 我已经试过了:

$db = &JFactory::getDBO(); 
$id = JRequest::getString('id'); 
$db->setQuery('SELECT #__categories.params FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '. $db->quote($id)); 
$category = $db->loadResult();
echo $category; 

结果是这样的:

{"category_layout":"","image":"images\/u14115.png"}

但是如何从这个 JSON 字符串中只提取图像呢?

【问题讨论】:

    标签: php joomla joomla3.0 joomla-template


    【解决方案1】:

    您必须对字符串进行解码。试试 PHP 的 json_decode。添加到您的代码中:

    对象:

    $category = json_decode($category);
    echo $category->image;
    

    数组:

    $category = json_decode($category, true);
    echo $category['image'];
    

    http://php.net/manual/en/function.json-decode.php

    您也可以在 Joomla 中通过以下方式本地执行此操作:

    $category = JCategories::getInstance('Content')->get($id);
    echo $category->getParams()->get('image');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 2023-04-09
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多