0

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?

labilbe
  • 3,501
  • 2
  • 29
  • 34

2 Answers2

0

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

max234435
  • 587
  • 5
  • 18
  • Thanks ill give this a try when I get home. The issue is that the values have no problem if they are not nested into an if statement. Not sure why the if's as causing a problem or what is causing it to not be readable. – Eric Beaudoin Mar 29 '16 at 11:16
  • Seems like the issue is.not woth the values but rather with the first div. If I echo test brfore and after the code it.appears in my aricle. (Including load position to load this article). But.the actual table is showing up under my footer and its not wraped in a div. What is happening to the div andbwhy isnt the table in my article too. You can see the results on an error page. http://www.Clearlove.ca/jsh – Eric Beaudoin Mar 29 '16 at 12:30
  • }elseif ($this->category->ogimages){ this is on line 227, its a vatiable i added in the bavkend to articles to se a url for an image. The weird thing is that the newsflash doesnt shoebthis error.if.i dont.have the if statements in the for each – Eric Beaudoin Mar 29 '16 at 18:28
  • Thats where your problem is. See if you can take that statement out and if it will still work. I have a feeling that you are not getting a category or ogimages into the variable and its trowing an errors. Or wrap that statement with `isset($this->category->ogimages)` – max234435 Mar 29 '16 at 18:31
  • Ok so that error went away but caused another so I did isset again and went away. But.im still having the same.issue. also getting.direct php errors whjich i had before. – Eric Beaudoin Mar 29 '16 at 18:59
  • I have never dealt with joomla but I do use Laravel quite extensively, so i'm going to assume that you have database relationships feeding variables that you are trying to output in view. In saying that, there are probaly some entries have `ogimage` and some dont. So when you are trying to output the entry that does not have `ogimage` php is yelling at you. This is why I use `isset` because in the instance that you don't have that category attached to the object, php does not display anything since it doesnt have anything to display and does not throw and error – max234435 Mar 29 '16 at 20:30
  • You need to look at the records where the information is coming from....and make sure everything you are trying to tell php to output is actually present there. Check your SQL and such. Hope that helps – max234435 Mar 29 '16 at 20:31
  • still not sure because as soon as I remove the if statements within the for loop it works. I don tunderstand how putting some if statements to add html tables would mess up? On further investigation I can see with out the if statements, my article as the list of articles in a div, but after i put the ifs the div extends to the rest of the page so that there is also the footers now nested in the div. instead of
    its more like
    – Eric Beaudoin Mar 29 '16 at 20:48
  • Hey, if you look at my reply, I figured it out! – Eric Beaudoin Mar 29 '16 at 21:15
  • Glad to hear you got it figured out! – max234435 Mar 29 '16 at 22:23
0

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!