Output the Titles of the 10 Most Recent Articles in a Specific Section

The PHP example code below shows how to use OnpubAPI to output a bulleted list of titles of the 10 most recent articles from a specific Onpub section.

<?php

include 'onpub/api/onpubapi.php';

// Establish the connection to the Onpub database.
$pdo = new PDO("mysql:host=localhost;dbname=test""test""test");

$oArticles = new OnpubArticles($pdo);

$qo = new OnpubQueryOptions();
$qo->orderBy 'created';
$qo->order 'DESC';
$qo->rowLimit 10;

// Select 10 articles from section 2 sorted by date created in descending order.
$articles $oArticles->select($qo2);

// Print the title of each article in a bulleted list.
echo '<ul>';

foreach (
$articles as $a) {
  echo 
'<li>' $a->title '</li>';
}

echo 
'</ul>';

?>

Comments

Feel free to comment on this article below. Any abusive/offensive material will be removed without notice.

blog comments powered by Disqus