lorenzop
lorenzop

Reputation: 600

PHP script to get all article IDs joomla

I developed a script which give me the text of a Joomla article from its ID, something like this:

$article =& JTable::getInstance("content");
$article->load($address = JRequest::getVar('articleID'));
echo $article->get("introtext");
echo $article->get("fulltext");

Now I need a similar script to get ALL (active) article IDs of the current site (maybe ordered from the last to the first like on the joomla homepage).

I gave a look around but couldn't find anything.

Thanks in advance

Upvotes: 1

Views: 3078

Answers (1)

Lodder
Lodder

Reputation: 19733

You could use the following:

$query = "SELECT * FROM #__content";
$db = JFactory::getDBO();
$db->setQuery($query); 
$articles = $db->loadObjectList(); 
foreach($articles as $article){
    echo 'ID:' . $article->id . ' Title: ' . $article->title;
}

If you want to get all the ID's of articles from a specific category, you could use the following:

$catId = 59;
$query = "SELECT * FROM #__content WHERE catid ='" . $catId . "'";
$db = JFactory::getDBO();
$db->setQuery($query); 
$articles = $db->loadObjectList(); 
foreach($articles as $article){
    echo 'ID:' . $article->id . ' Title: ' . $article->title;
}

Obviously you change 59 to whatever suits your needs

Note that this method of a database query is for Joomla 1.5

Hope this helps

Upvotes: 2

Related Questions