Most popular articles in toc

I am trying to display the most popular articles block on the journal table of content instead of displaying it on either right or left side .

Hi @Ahmad_Al_Jayousi,

That’ll require modifying the code; currently it’s only written to appear on the sidebar.

Regards,
Alec Smecher
Public Knowledge Project Team

can you guide me to do so

Hi @Ahmad_Al_Jayousi,

I’m sorry, but we can’t guide you through modifications to the system. If you are familiar with PHP/MySQL and have specific questions, we should be able to help.

Regards,
Alec Smecher
Public Knowledge Project Team

Yes I am a PHP/MySQL Programmer. How can I apply this knowledge to the aforementioned issue

Hi @Ahmad_Al_Jayousi,

You’ll need to assign some content to the template manager, then add the template code to present it where you want. The assignment in the block plugin happens in MostPopularArticlesBlockPlugin in the “getContents” function; you’ll need to transplant that into a handler.

The template code is in the plugins’ block.tpl Smarty template. You’ll see that it makes use of the variables assigned in getContents.

As for where you put this code, the table of contents is presented in pages/issue/IssueHandler.inc.php in the “current” (current issue) and “view” functions (other issues). They refer to templates – you can find those files in the templates/ subdirectory.

The OJS technical reference will probably be useful; it’s available from our Documentation page.

Regards,
Alec Smecher
Public Knowledge Project Team

Dear @asmecher

I tried to do so , but always fail to display the returned results

Can you help me more. I need to solve this issue as fast as possible

regards

Hi @Ahmad_Al_Jayousi,

If you can post your modifications as a fork on github.com, I can have a quick look.

Regards,
Alec Smecher
Public Knowledge Project Team

I put this function in IssueHandler.inc.php

function getContents(&$templateMgr) {
	$journal =& Request::getJournal();
	if (!$journal) return '';

	$mostPopularArticlesDAO =& DAORegistry::getDAO('MostPopularArticlesDAO');
	$templateMgr->assign('popularArticles', $mostPopularArticlesDAO->getMostPopularArticles($journal->getJournalId(), 5));

	$journalDao =& DAORegistry::getDAO('JournalDAO');
	$templateMgr->assign_by_ref('journalDao', $journalDao);
	return parent::getContents($templateMgr);
}

and this code in issue.tpl

{translate key="plugins.blocks.popularArticles.displayName"} - TOP 5
 
{foreach from=$popularArticles item=articleInfo} {assign var=iterator value=$articleInfo.article} getArticleId()}" style="line-height:1.5; font-family: georgia; font-size: 13px; font-weight: normal; color: #fff;">
{$iterator->getArticleTitle()}
 
{$articleInfo.views} {translate key="plugins.blocks.popularArticles.viewsSince"}: {$iterator->getDatePublished()|date_format:$dateFormatShort}
 
{/foreach}

Hi @Ahmad_Al_Jayousi ,

The Handler classes don’t use a getContents function – that’s only for block plugins. Have a look at the technical reference for some details on how Handler classes work.

Regards,
Alec Smecher
Public Knowledge Project Team