« Project home page

phpSQLiteCMS Forum

Back to the forum index
Linear

News Headlines on Index Page (Technics)

by Ryan, Sunday, May 30, 2010, 19:12 (101 days ago)

Hi,

Anybody have a quick easy way of displaying a 'latest new' list of titles/links to news articles on the main index page?

News Headlines on Index Page

by Ryan, Friday, June 11, 2010, 11:26 (89 days ago) @ Ryan

I love this thing!

Anyway, to save time for those getting started...

set content_function to 1 in Administration → Settings → Advanced settings

Throw the php function below into includes/functions.inc.php and edit as necessary

--------------------------------------
function get_latest_news_headlines($limit) {
$dbr = Database::$content->query("
SELECT page, title, time FROM ".Database::$db_settings['pages_table']." WHERE sections = 'news' AND content_type = '' AND status > 0 AND NOT type = 'news' ORDER BY time DESC LIMIT " . $limit);
$headlines = '';
while ( $row = $dbr->fetch() ) {$headlines .= "<li><a href=\"" . $row['page'] . "\">" . $row['title'] . "</a><span class=\"timestamp\"> " . date("l, M j, Y",$row['time']) . "</span></li>";}
return $headlines;
}
--------------------------------------

and add the following into the index page.

<ul id="headlines">
[function:get_latest_news_headlines(5)]
</ul>

News Headlines on Index Page

by moho, Friday, June 11, 2010, 16:02 (89 days ago) @ Ryan

Ryan, Great job. After Section="news" what is the purpose of a null Content_type condition?

News Headlines on Index Page

by Ryan, Friday, June 11, 2010, 18:42 (89 days ago) @ moho

you could pull the content_type condition out of the query, it was left there from testing. '' is the default value for content_type as far as the database is concerned, and phpsqlitecms interprets the '' value as text/html.

News Headlines on Index Page (using simple news)

by Ryan, Wednesday, June 23, 2010, 18:38 (77 days ago) @ Ryan
edited by Ryan, Wednesday, June 23, 2010, 19:26

Here's a function for grabbing the latest simple news headlines as links. Use $limit to determine how many headlines to show at the most.

NOTE: place this function in functions.content.inc.php (new) instead of functions.inc.php as mentioned in my firt post.

function get_simple_news_headlines($limit) {
  $dbr = Database::$content->query("
  SELECT newsitem.id, newsitem.title, newsitem.time, page.page
  FROM ".Database::$db_settings['news_table']." AS newsitem
  LEFT JOIN ".Database::$db_settings['pages_table']." AS page
  ON newsitem.page_id = page.id
  ORDER BY newsitem.time DESC
  LIMIT " . $limit
  );
  $headlines = '';
  while($row=$dbr->fetch()){
    $headlines .= "<li><a href=\"". $row['page'] .",". $row['id'] ."\">". $row['title'] ."</a> <span class=\"timestamp\">".date("M jS, Y, g:i a",$row['time'])."</span></li>";
  }
  return $headlines;
}

Call the function from any page content like so ...

<ul>[function:get_simple_news_headlines(5)]</ul>
RSS Feed of thread
192 Postings in 89 Threads, 63 registered users, 6 users online (0 registered, 6 guests)
Forum time: 2010-09-08, 15:18
RSS Postings  RSS Threads | Contact
powered by my little forum