Joomla 3.4使用blog_item覆盖com_content / default_articles.php

时间:2015-07-23 08:33:51

标签: php joomla override

我正在处理类别覆盖(com_content / category /)并尝试直接在其类别下显示每个类别的项目

像这样:

maincat(com_content / category / default_articles.php)

-cat 1(com_content / category / default_children)

- undercat1 1(com_content / category / blog_item.php)

- undercat1 2

所以我需要将blog_item.php中的代码插入default_articles或default_children

这个

<div class="test"> 
  <?php echo $this->item->event->beforeDisplayContent; ?>
   <?php echo $this->item->introtext; ?>  
</div>

需要进入default_articles但我得到属性错误,也尝试使用不同的变量名称 - 相同的错误。 错误:

注意:第66行的D:\ xampp \ htdocs \ joomla \ templates \ protostar \ html \ com_content \ category \ default_children.php中的未定义属性:stdClass :: $ event

注意:尝试在第66行的D:\ xampp \ htdocs \ joomla \ templates \ protostar \ html \ com_content \ category \ default_children.php中获取非对象的属性

注意:第66行的D:\ xampp \ htdocs \ joomla \ templates \ protostar \ html \ com_content \ category \ default_children.php中的未定义属性:stdClass :: $ introtext

来自default_children.php的第66行:

<?php echo $this->item->event->beforeDisplayContent; ?> <?php echo $this->item->introtext; ?>

(这行最初来自com_content / category / blog_item.php,我希望它在default_children.php中)

default_children.php

 <?php
 /**
 * @package     Joomla.Site
 * @subpackage  com_content
  *
  * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All      rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
   */

  defined('_JEXEC') or die;

   JHtml::_('bootstrap.tooltip');

   $lang    = JFactory::getLanguage();
    $class = ' class="first"';
        ?>

   <?php if (count($this->children[$this->category->id]) > 0) : ?>
  <?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
      <?php
    if ($this->params->get('show_empty_categories') ||       $child->getNumItems(true) || count($child->getChildren())) :
        if (!isset($this->children[$this->category->id][$id + 1])) :
            $class = ' class="last"';
          endif;
    ?>

    <div<?php echo $class; ?>>
        <?php $class = ''; ?>
        <?php if ($lang->isRTL()) : ?>
        <h3 class="page-header item-title">
            <?php if ( $this->params->get('show_cat_num_articles', 1)) : ?>
                <span class="badge badge-info tip hasTooltip" title="<?php    echo JHtml::tooltipText('COM_CONTENT_NUM_ITEMS'); ?>">
                    <?php echo $child->getNumItems(true); ?>
                </span>
            <?php endif; ?>
            <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($child->id));?>">
            <?php echo $this->escape($child->title); ?></a>

            <?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
                <a href="#category-<?php echo $child->id;?>" data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
            <?php endif;?>
        </h3>
        <?php else : ?>
        <h3 class="page-header item-title"><a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($child->id));?>">
            <?php echo $this->escape($child->title); ?></a>
            <?php if ( $this->params->get('show_cat_num_articles', 1)) : ?>
                <span class="badge badge-info tip hasTooltip" title="<?php echo JHtml::tooltipText('COM_CONTENT_NUM_ITEMS'); ?>">
                    <?php echo $child->getNumItems(true); ?>
                </span>
            <?php endif; ?>

            <?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
                <a href="#category-<?php echo $child->id;?>" data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
            <?php endif;?>
        <?php endif;?>
        </h3>
        <?php if ($this->params->get('show_subcat_desc') == 1) :?>
            <?php if ($child->description) : ?>
                <div class="category-desc">
                    <?php echo JHtml::_('content.prepare', $child->description, '', 'com_content.category'); ?>
                </div>
            <?php endif; ?>
        <?php endif; ?>

          <div class="test">   <?php echo var_dump($this->item) ?>   </div>
        <?php echo $this->item->event->beforeDisplayContent; ?> <?php echo $this->item->introtext; ?>


        <?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) :?>
        <div class="collapse fade" id="category-<?php echo $child->id;?>">
            <?php
            $this->children[$child->id] = $child->getChildren();
            $this->category = $child;
            $this->maxLevel--;
            echo $this->loadTemplate('children');
            $this->category = $child->getParent();
            $this->maxLevel++;
            ?>
        </div>
        <?php endif; ?>

    </div>
    <?php endif; ?>
<?php endforeach; ?>

'

我对PHP还不是很好 - 可能你们中的一些人可以给我一个解决方案的暗示?

谢谢

1 个答案:

答案 0 :(得分:0)

我不确定你要做什么,但我认为你对a模板正在做的事感到困惑。它不显示文章,它显示有关定义博客的类别的任何子类别的信息。因此,在您发布的代码中,您看不到对default_children的任何引用,您看到$item的引用。类别没有$child他们introtext,因此您看到description

您要覆盖的文件是$child->description。如果您查看那里,您会看到default_articles的引用,以便告诉您可能需要$article->created_by_alias