Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Random News Panel Infusion


Print Track
Is anyone aware of an infusion/panel that provides random news posts? If so, where can I download it. I found a random articles infusion/panel but I don't have the coding skills to adapt it to pulling news posts.

5 replies

Hello, please state the news infusion version please.

The reason being the latest news infusion doesn't have news image information on the same table and have better filter searching using OOP.

For random news, typical, you can just code into the panel itself with Allow PHP Execution settings turned on if you're on Version 9. Just drop the code into a new panel.


CodeDownload  

$result = dbquery("SELECT * FROM ".DB_NEWS." ORDER BY rand() LIMIT 10");
if (dbrows($result)) {
 while ($data = dbarray($result)) {
 // do your news design here.
 print_p($data);
 }
}

Thanks for your response Chan. I am trying to adapt the random_articles_panel into a random_news_panel that will work with either 7.02.07 and/or 8.00.21.

I have tried to adapt the code from random_arcticles_panel and am making progress except that instead of pulling up the news_id from the random pull, it is pulling up all of the news items on the website. I will keep trying and will update the forum with my results.
If you want, you can try to test the panel for PF-7.02 - Related News
CodeDownload  


//----------*Related News panel*--------------//

if ((FUSION_SELF == 'news.php') && isset($_GET['readmore']) && isNum($_GET['readmore']))
 {
 list($news_subject) = dbarraynum(dbquery("SELECT news_subject from ".DB_NEWS." WHERE news_id=".$_GET['readmore']));
 
 $rel_news_res = dbquery("SELECT news_id, news_subject, news_news, news_image FROM ".DB_NEWS." WHERE MATCH (news_subject) AGAINST ('".$news_subject."' IN BOOLEAN MODE) AND news_id != ".$_GET['readmore']." ORDER BY news_datestamp DESC LIMIT 10");

$langPanel['001'] = "Related News:";
$counter = 0;
$columns = 2; //number of columns per line
 
 if(dbrows($rel_news_res))
 {
 opentable($langPanel['001']);
 echo "<table width='100%'>\n<tr>\n";
 while($news = dbarray($rel_news_res))
 {
 if ($counter != 0 && ($counter % $columns == 0)) // comment out if you want to output in one line
echo "</tr>\n<tr>\n";
 echo "<td width='50%'>\n";
echo "<table cellpadding='4' cellspacing='2' width='100%'>\n<tr>\n";
 echo "<td><a href='".BASEDIR."news.php?readmore=".$news['news_id']."' alt='".$news['news_subject']."'><img src='".IMAGES_N."".$news['news_image']."' title='".$news['news_subject']."' width='96%' height='auto' /></a><strong><a href='".BASEDIR."news.php?readmore=".$news['news_id']."'>".trimlink(strip_tags(stripslashes($news['news_subject'])), 39)."</a></strong>".trimlink(strip_tags(stripslashes($news['news_news'])), 69)."</td>\n</tr>\n";
 echo "</table>\n</td>\n";
 $counter++; // comment out if you want to output in one line
   }
 echo "</tr>\n</table>\n";
 closetable();
 }
 }
//-------------*The end*--------------//



Embed code in the file news.php
Below the line:
CodeDownload  
echo "<!--news_sub_readmore-->"; 


Search at the bottom of the code https://github.com/php-fusion/PHP-Fus...s.php#L138
I have been able to adapt the random_articles_panel code to work with random_news_panel and it works by displaying one news item at a time randomly. I will try your code however zizub and see how that works.

Merged on 05/25/2019:
Zizub, after adding your code, all that was displayed were blank squares where I assume images were supposed to show. This is below the news article that I was trying to read. What images is it supposed to be pulling up?
Excuse me. I forgot to say that my news is slightly modified. My image in the thumbs (t1 and t2) folder is ignored.
This panel shows news with similar words in the title.
The panel shows images from the ..images/news/xxx.jpg folder.
The picture for the news is added via the button: Select file. See attached photo
zizub attached the following image:
author afoster
forumPanels and Infusions
replies6 posts
viewed332 times
activeLast updated on 3 months ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: afoster, Chan, zizub