dtp0760 2016-03-29 04:32
浏览 81

将文章newsflash设置为表格

Hi I am trying to turn article newsflash into a list of links in a table. I remove intro text by commenting it out so that it will only show the article title, and alter the tmpl files.

This is a php file called links. I duplicated vertical.php from modules/mod_article_news and then put this info instead.

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

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

echo '<div class="newsflash-vert">';
for ($i = 0, $n = count($list); $i < $n; $i ++) {
    $item = $list[$i]; 
if ($i==0){
echo "<table>";
}

if ($i & 1){
//odd
}else{
//even
echo "<tr>";
}
echo "<td>";
    echo '<div class="newsflash-item">';
     require JModuleHelper::getLayoutPath('mod_articles_news', '_item_links');
    if ($n > 1 && (($i < $n - 1) || $params->get('showLastSeparator'))) {
        echo '<span class="article-separator">&#160;</span>';
    }
    echo '</div>';

echo "</td>";
if ($i & 1){
//odd
}else{

if ($i == $n){
echo "</tr>";
}
}
if ($i == $n){
//end
echo "</table>";
}
}
echo "</div>";

I also duplicatied _item.php and renamed it to _item_links and have this php code:

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

// no direct access
defined('_JEXEC') or die;
$item_heading = $params->get('item_heading', 'h4');
?>
<?php if ($params->get('item_title')) : ?>

    <<?php echo $item_heading; ?> class="newsflash-title<?php echo $params->get('moduleclass_sfx'); ?>">
    <?php if ($params->get('link_titles') && $item->link != '') : ?>
        <a href="<?php echo $item->link;?>">
            <?php echo $item->title;?></a>
    <?php else : ?>
        <?php echo $item->title; ?>
    <?php endif; ?>
    </<?php echo $item_heading; ?>>

<?php endif; ?>

<?php if (!$params->get('intro_only')) :
    echo $item->afterDisplayTitle;
endif; ?>

<?php echo $item->beforeDisplayContent; ?>

<?php //echo $item->introtext; ?>

<?php if (isset($item->link) && $item->readmore != 0 && $params->get('readmore')) :
    echo '<a class="readmore" href="'.$item->link.'">'.$item->linkText.'</a>';
endif; ?>

Then I was going to make it look nicer with css, but I am getting an error in my error_log: [29-Mar-2016 00:19:58 America/New_York] PHP Notice: Trying to get property of non-object in /home/loverevo/public_html/clearlove/templates/clearlove_home/html/com_content/article/view.html.php on line 217

This error goes away when I put the file back, I believe it has something to do with my if statements. But I am not sure. I also tried the code with out having it all as php, and using a lot of leaving all the html as just html and not echoed.

Not sure what is causing this, any one have any ideas?

</div>
  • 写回答

2条回答 默认 最新

  • dongxixia6399 2016-03-29 04:48
    关注

    Check your code and make sure your variables that you are trying to echo out actually have a value. I'm pretty sure its yelling at you for example if you are trying to call $item->title but the $item itself does not have a value passed into it. So its saying that you are trying to get a title but the object $item doesnt exist or is something other than an object.

    I would do this before going into the $item object:

    if ($item) {
    
        echo $item->title;
    echo $item->value2;
    
    }
    

    or if some of your object values sometimes dont have a value attached, check the actual value before outputting

    $itme->value1 ? $item->value1 : "";
    

    hope that helps

    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化