Joomla K2在generic.php上显示了额外的字段

时间:2012-12-11 14:49:30

标签: php mysql joomla joomla-k2

我们正在开发一个基于k2的网站。为此,我们利用extrafields给文章一个特定的css类。

但是当我们使用归档扩展时,这个类没有应用,我们收到错误。

这是我们得到的错误

  

警告:为foreach()提供的参数无效   /home/recall/domains/domain.com/public_html/templates/mytemplate/html/com_k2/generic.php   第19行

这是代码

<!-- START: Call to prepare extra fields -->
<?php  
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{    
$extrafields[$item->id] = $item->value;
}   
?>    
<!-- END: Call to prepare extra fields -->

<!-- Start K2 Generic (search/date) Layout -->
<div id="k2Container" class="genericView<?php echo $this->escape($this->params->get('page-id')); ?> nieuwsarchief">

        <?php if($this->params->get('genericFeedIcon',1)): ?>
        <!-- RSS feed icon -->
        <ul class="k2SendReceiveNews">
                <li class="legende_bestuur"><span>Bestuur</span></li>
                <li class="legende_regio"><span>Regio</span></li>
                <li class="legende_school"><span>School</span></li>
                <li><a href="#">Nieuws melden</a></li>
                <li><a href="#">Nieuws via e-mail ontvangen</a></li>
                <li class="rssfeed"><a href="<?php echo $this->feed; ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?>">
                        <span><?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?></span>
                </a></li>
                <div class="clr"></div>
        </ul>
        <?php endif; ?>

        <?php if($this->params->get('show_page_title')): ?>
        <!-- Page title -->
        <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
                <?php echo $this->escape($this->params->get('page_title')); ?>
        </div>
        <?php endif; ?>

        <?php if(count($this->items)): ?>
        <div>
                <?php foreach($this->items as $item): ?>

                <!-- Start K2 Item Layout -->
                <div class="CatItem-<?php echo $extraFlds['Nieuwscategorie']; ?>">
                <?php
echo $item->extra_fields[11]->value;
?>

                        <div class="catItemContent catItemHeader">

                          <?php if($this->params->get('genericItemTitle')): ?>
                          <!-- Item title -->
                          <h3 class="catItemTitle">
                                <?php if ($this->params->get('genericItemTitleLinked')): ?>
                                        <a href="<?php echo $item->link; ?>">
                                        <?php echo $item->title; ?>
                                </a>
                                <?php else: ?>
                                <?php echo $item->title; ?>
                                <?php endif; ?>
                          </h3>
                          <?php endif; ?>
                          <?php if($this->params->get('genericItemDateCreated')): ?>
                                <!-- Date created -->
                                <span class="genericItemDateCreated">
                                        <?php echo JHTML::_('date', $item->created , JText::_('DATE_FORMAT_LC10')); ?>
                                </span>
                                <?php endif; ?>
                  </div>

                </div>
                <!-- End K2 Item Layout -->

                <?php endforeach; ?>
        </div>

        <!-- Pagination -->
        <?php if($this->pagination->getPagesLinks()): ?>
        <div class="k2Pagination">
                <?php echo $this->pagination->getPagesLinks(); ?>
                <div class="clr"></div>
                <?php echo $this->pagination->getPagesCounter(); ?>
        </div>
        <?php endif; ?>

        <?php endif; ?>

</div>
<!-- End K2 Generic (search/date) Layout -->

我自己找到了解决方案。

这是最终代码:

<?php
/**
 * @version     $Id: generic.php 1618 2012-09-21 11:23:08Z lefteris.kavadas $
 * @package     K2
 * @author      JoomlaWorks http://www.joomlaworks.net
 * @copyright   Copyright (c) 2006 - 2012 JoomlaWorks Ltd. All rights reserved.
 * @license     GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

// no direct access
defined('_JEXEC') or die;

?>

<!-- Start K2 Generic (search/date) Layout -->
<div id="k2Container" class="genericView<?php echo $this->escape($this->params->get('page-id')); ?> nieuwsarchief">

    <?php if($this->params->get('genericFeedIcon',1)): ?>
    <!-- RSS feed icon -->
    <ul class="k2SendReceiveNews">
        <li class="legende_bestuur"><span>Bestuur</span></li>
        <li class="legende_regio"><span>Regio</span></li>
        <li class="legende_school"><span>School</span></li>
        <li><a href="#">Nieuws melden</a></li>
        <li><a href="#">Nieuws via e-mail ontvangen</a></li>
        <li class="rssfeed"><a href="<?php echo $this->feed; ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?>">
            <span><?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?></span>
        </a></li>
        <div class="clr"></div>
    </ul>
    <?php endif; ?>

    <?php if($this->params->get('show_page_title')): ?>
    <!-- Page title -->
    <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
        <?php echo $this->escape($this->params->get('page_title')); ?>
    </div>
    <?php endif; ?>

    <?php if(count($this->items)): ?>
    <div>

        <?php foreach($this->items as $item): ?>

        <!-- START: Call to prepare extra fields -->
        <?php
        //convertArray to use ids as key
        $extrafields = array();
        foreach($item->extra_fields as $extraFlds)
        {    
        $extrafields[$extraFlds->id] = $extraFlds->value;
        }   
        ?>    
        <!-- END: Call to prepare extra fields -->

        <!-- Start K2 Item Layout -->
        <div class="CatItem-<?php echo $extrafields[11];?>">

            <div class="catItemContent catItemHeader">

              <?php if($this->params->get('genericItemTitle')): ?>
              <!-- Item title -->
              <h3 class="catItemTitle">
                <?php if ($this->params->get('genericItemTitleLinked')): ?>
                    <a href="<?php echo $item->link; ?>">
                    <?php echo $item->title; ?>
                </a>
                <?php else: ?>
                <?php echo $item->title; ?>
                <?php endif; ?>
              </h3>
              <?php endif; ?>
              <?php if($this->params->get('genericItemDateCreated')): ?>
                <!-- Date created -->
                <span class="genericItemDateCreated">
                    <?php echo JHTML::_('date', $item->created , JText::_('DATE_FORMAT_LC10')); ?>
                </span>
                <?php endif; ?>
          </div>

        </div>
        <!-- End K2 Item Layout -->

        <?php endforeach; ?>
    </div>

    <!-- Pagination -->
    <?php if($this->pagination->getPagesLinks()): ?>
    <div class="k2Pagination">
        <?php echo $this->pagination->getPagesLinks(); ?>
        <div class="clr"></div>
        <?php echo $this->pagination->getPagesCounter(); ?>
    </div>
    <?php endif; ?>

    <?php endif; ?>

</div>
<!-- End K2 Generic (search/date) Layout -->

对于正确的值,在k2额外字段的后端找到相应的id(右侧)

对我而言, id 11

<?php echo $extrafields[11];?>

0 个答案:

没有答案