Show a number of articles from the last few issues on Homepage

Hello,

Currently the platform shows the articles of the last issue in the homepage. What I would like is to show a number of articles, say 20 from the last few issues. So probably I have to iterate through the last issues in order and pick up the desired number of articles, title & abstract.

Could you please help me with this? I’ve tried a few things, but can’t seem to figure out how to do it - how it all relates.

I’m on OJS3. Thank you!

–Edit
If this isn’t possible could you please show me how to manually pull the title & summary of certain articles by their issue & article number? I’m thinking of listing these articles manually on the Homepage if push comes to shove.

I did not test this, but you could try something like this. The code goes to your themeplugin file and of course you will also need a modified frontpage template that will loop through the articles that are being fetched. For instructions see https://pkp.gitbooks.io/pkp-theming-guide/content/en/advanced-custom-data.html

public function loadTemplateData($hookName, $args) {		
		
		// Start Latest articles

		$latestArticles = array();

		// Fetch latest published article id's
		$articleDao = DAORegistry::getDAO('PublishedArticleDAO');
		$result = $articleDao->retrieve("SELECT submission_id FROM published_submissions ORDER BY date_published DESC LIMIT 20");
		

		while (!$result->EOF) {
			$resultRow = $result->GetRowAssoc(false);
			
			// get an article object for the given id	
			$article = $articleDao->getById($resultRow['submission_id']);
			
			// Store the needed values for the template loop, this could include other data as well
			$latestArticles[$article->getId()]['title'] = $article->getLocalizedTitle();
			$latestArticles[$article->getId()]['path'] = $article->getBestArticleId();
			$latestArticles[$article->getId()]['authors'] = $article->getAuthors();

			$result->MoveNext();

		}

		$result->Close();

		// assign the values for the front page template
		$templateMgr->assign('latestArticles', $latestArticles);

		// End Latest articles
		
	}
1 Like

Thank you very much! Your answer helped a lot!

I included the code in the themeplugin file with minor changes, templateMgr wasn’t loaded, and I wanted the full article object:

	public function init() {
	HookRegistry::register('TemplateManager::display', array($this, 'loadTemplateData'));
}

	public function loadTemplateData($hookName, $args) {
	// Start Latest articles
	$articles = array();
	$latestArticles = array();

	// Fetch latest published article id's
	$articleDao = DAORegistry::getDAO('PublishedArticleDAO');
	$result = $articleDao->retrieve("SELECT submission_id FROM published_submissions ORDER BY date_published DESC LIMIT 10");

	$issueDao = DAORegistry::getDAO('IssueDAO');

	while (!$result->EOF) {
		$resultRow = $result->GetRowAssoc(false);

		// get an article object for the given id
		$article = $articleDao->getById($resultRow['submission_id']);
		$latestArticles[0]['articles'][] = $article;
		$latestIssueData[$resultRow['submission_id']] = $issueDao->retrieve("SELECT * FROM published_submissions WHERE submission_id = '{$resultRow['submission_id']}';")->GetRowAssoc(false);

		$result->MoveNext();
	}

	$result->Close();

	// Retrieve the TemplateManager
        $templateMgr = $args[0];

	// assign the values for the front page template
	$templateMgr->assign('latestArticles', $latestArticles);
	$templateMgr->assign('latestIssueData', $latestIssueData);

	// End Latest articles
}

And then copied templates/frontend/objects/issue_toc.tpl to my theme and changed $publishedArticles to $latestArticles - for the article display, this is pretty much it! Thank you very much!

I needed some extra data about the articles to display in article_summary.tpl, like the issue where the article is published and the publish date, so I got them in another array using the same idea. I don’t know if it’s the right approach, but it did the trick. If you know of another way, more elegant perhaps, to get this additional data, I’d like to look into it…

Other ways I’d consider this topic as closed. The info you gave is really valuable also if one wants to make a ‘featured articles’ page also.

1 Like

I am not sure how it is working at the moment, but with my original approach I would probably do something like:
$issue = $issueDao->getById($article->getIssueId());
$latestArticles[$article->getId()][‘issue’] = $issue->getIssueIdentification();

As you can see my approach is to generate a custom array that you loop through so you can not use the original templates out of the box. But the modifications needed to the basic TOC loop are fairly small.

1 Like