TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 202
  • Total: 202

Articles Block question

Started by DonaldDasher, September 14, 2008, 01:12:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DonaldDasher

How do I display titles and links to recently created articles in the Articles block?

JPDeni

You want a list of articles, sorted by date, with the most recent at the top? What exactly do you want to display? Just the title and link? Or do you want the date as well? Intro? Author? Number of views? Number of comments? Rating?

DonaldDasher

Just the title and a link would be good. A date would be nice too I guess.

I've tried looking at the block's settings but I can't get it to display just what I need.

JPDeni

In a php block:


global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, id, date
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  echo '<a href="' . $scripturl . '?page=' . $row['id'] . '">' . $row['subject'] . '</a> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';
}

DonaldDasher

#4
Perfect - thanks!

JPDeni

I saw that you wanted to modify this to use the short title.


global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, shortname, date
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';
}


That should work.

DonaldDasher

Yes, it works fabulously - thanks again ;)

Ianedres

Actually, JP, that latest version won't link properly if the 'shortname' has no value. I added the 'if' clause to swap to the article's id number if 'shortname' was empty.

global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, id, date, shortname
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if(empty($row['shortname'])) $row['shortname'] = $row['id'];

  echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';
}

JPDeni


This website is proudly hosted on Crocweb Cloud Website Hosting.