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.
Not a member yet? Click here to register.
Forgot Password?

Random News Panel Infusion

Asked Modified Viewed 1,441 times
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
asked
Senior Member

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.
0 replies

5 posts

C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

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.



$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);
 }
}
Edited by Chan on 24-05-2019 06:25,
0 replies
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
answered
Senior Member

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.
0 replies
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
answered
Member

If you want, you can try to test the panel for PF-7.02 - Related News


//----------*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:
echo "<!--news_sub_readmore-->"; 

Search at the bottom of the code https://github.com/PHPFusion/PHPFusio...s.php#L138
Edited by zizub on 25-05-2019 16:18,
0 replies
A
afoster
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
answered
Senior Member

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?
0 replies
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
answered
Member

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
Edited by zizub on 25-05-2019 23:42,
zizub attached the following image:
Image not found
0 replies

Category Forum

Panels and Infusions

Labels

None yet

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

A
A
  • Senior Member, joined since
  • Contributed 725 posts on the community forums.
  • Started 128 threads in the forums
  • Started this discussions
C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
Z
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet