将文章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>

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

There are several issues in the code. The first and major issue is that I am trying to end the table using a condition if $i == $n. but the for statement only loops as long as $i < $n, therefore I have to have my condition to end the table should be $i == $n -1;

Also as regards to my previous code, putting isset works so that the code is not processed if not set in a few different areas. I am going to look further into this as I was not getting this issue before but for now it works!