How to add most read topics in ojs 3.1?



In OJS 3.1 that function is called getPublishedArticleById (in 3.0.2 it was getPublishedArticleByArticleId)


Hello! @ajnyga, @dennisbr and @varshilmehta

I would like to be able to install this plugins in one of the boostrap child themas for OJS 3.1.0-1

Could someone make it work properly?

Can you guide me in the files that I have to modify and the codes that I should include?



It didnt work for me.


The code is from our site level theme plugin so the problem is probably connected to that, but without hands-on testing hard to say what the problem is. It does work fine in our case of course and is used in our production server.

I can not promise anything but I will see if I have time to do a child theme of the bootstrap theme with this addition at some point.


yo estoy tratando de crear uno a nivel de journal, para el tema bootstrap, pero me da errores 500 con algunas funciones del php, en cuanto lo solucione lo publico


para que version de OJS tienes ese plugins.?


The code above was for 3.0.2 and the current version we use is for, but it is almost the same


puedes publicar el codigo…? para probarlo, porque el que estaba modificando para el tema bootstrap me da muchos errores en el php


It is available here:
edit: but as I said, this is not a theme for a journal but for the front page of


Just fyi that I created this simple block plugin that uses the same code as my site theme.

It shows the most dowloaded articles for the last 7 days. Should be fairly easy to edit. If someone wants to make it more versatile (add some settings for the time limits, include abstract views etc.) you are of course welcome to copy the code.


Hi @ajnyga
Instead of a block plugin, can the codes to call the most read articles in the plugin be implemented in indexJournal.tpl for example? If it can, which codes?


I want to change the range of the time, e.g. 30 days. I initially guessed to do it why changing the

		$currentDate = date('Ymd');
		$weekAgo = date('Ymd', strtotime("-1 week")); --> to "-4 week"

Is it a right method?


It is a standard strtotime function. That should work I think. Also “4 weeks ago” should work (strtotime is a funny function) (see


The code from getContents goes to the init function in your theme plugin. How exactly this happens depends on the theme (I can not promise that I have time to give more detailed instructions)

The _cacheMiss function you just copy to the theme plugin file.

And finally you add the code form block.tpl to the template you want. Not the exact same code of course, but at least this


Before changing the time limit to 16 weeks, the metrics looks normal (below 50 reads) for one week. After setting to 16 weeks and back to one week, the metrics are not change.
How to change the number of articles shown?


The plugin creates a file cache. You have to delete the cache file to reflect the changes you make to the code.

The number of articles is in the SQL, “limit 5”


Sorry, but is this cache stored in the server or the client?


in the server, in cache folder. The same place where all OJS file cache files are stored.


Okay I found the cache file and was able to apply the changes to the function and see the difference

Now I’m sure that my problem is failing to retrieve the author’s name for each article:
I’m editting _cacheMiss():

while (!$result->EOF) {
    $resultRow = $result->GetRowAssoc(false);
    $article = $publishedArticleDao->getById($resultRow['submission_id']);
    $journal = $journalDao->getById($article->getJournalId());
    $articles[$resultRow['submission_id']]['journalPath'] = $journal->getPath();
    $articles[$resultRow['submission_id']]['articleId'] = $article->getBestArticleId();
    $articles[$resultRow['submission_id']]['articleTitle'] = $article->getLocalizedTitle();
    $articles[$resultRow['submission_id']]['metric'] = $resultRow['metric'];
    //$articles[$resultRow['submission_id']]['articleAuthors'] = $article->getAuthors();

… but $article->getAuthors() seems to be incorrect despite $article being a PublishedArticle.

Do you know if there’s an API reference for OJS 3 to find the function I need? I’m currently refering to OJS 2.4.8 by Doxygen.


The function is correct, but it does not return a string.

Maybe this example helps: