How to: Get a list of the most recent articles from any journal

Hi,

I am using OJS 3.3.0.10 and attempting to get a list of all articles to display on the home page. I used to be able to do this using the PublishedArticlesDAO but that no longer appears to work and I can’t find any recent examples of how to extract articles from the database.

Does anyone have a recent example of how to do this?

Hi @Ant_Forshaw
You can use the RSS plugin that shows the latest articles of the journal. And there you have an XML that you can use elsewhere.

Or if you need something different you can use the REST API - OJS

Thank you Dagosalas for the pointers. I’ve been looking at the API but also cannot find many (any) real life code examples of how to use it.

I should mention that I’m new to OJS and trying to learn it as quickly as possible within the time constraints of the current project I’m working on. Not making as much progress as I would have liked - it seems that everything I try simply doesn’t work for one reason or another. Some of the issues I’ve been facing have turned out to be down to changes in the class hierarchy, some are legitimate bugs within OJS and are being worked on and others are down to my lack of expertise with the system.

As it stands, I can’t even get a list of recently published articles out of the system because I can’t find any examples of how to do it!

Are you aware of any examples that people have posted that show working code? (Or does everyone else just read through the code base and try to ascertain how it works that way?)

Many thanks,

Anthony

Did you try the web feed plugin? This plugin produces RSS/Atom web syndication feeds for the current issue. (XML) . You can use this XML later for whatever you need.
Captura de Tela 2022-03-21 às 08.23.09

And you can see here:
Captura de Tela 2022-03-21 às 08.28.29

I think this is the fastest and most effective solution to have your latest posts and use them elsewhere.

Greetings!
–Dago

Thank You Dago - most helpful,

I have been able to use some of the code from the Web Feed plugin:-

$request = Application::get()->getRequest();
$journal = $request->getJournal();
$submissionsIterator = Services::get('submission')->getMany(['contextId' => $journal->getId(), 'status' => STATUS_PUBLISHED, 'count' => RCVSK_LATEST_ARTICLES_DEFAULT]);
$submissionsInSections = [];
foreach ($submissionsIterator as $submission) {
	$submissionsInSections[]['articles'][] = $submission;
}

That produces an array with several submission objects, which is a start, however the article display templates require an Article object itself - do you know how to create an article object that could be used by the article_card_horizontal.tpl template?

I could refactor the template to grab the values from the array but if there is a way to return article objects instead then that would be preferable.