Dear Community,
We all use the MostPopularArticles block plugin. In that plugin the author names are missing. I wonder if one can show me show it could be incorporated into plugin. (See attachments)
The original plugin appears like this:
How to make it like this:
1 Like
I modified the file at (/public_html/ojs-2.4.7-1/plugins/blocks/mostPopularArticles/MostPopularArticlesDAO.inc.php). Here I changed the following code:
$articlesInfo[$articleId] = array(
'article' => $article,
'views' => $count
);
with
$authors = $article->getAuthors();
$firstAuthor =& $authors[0];
$articlesInfo[$articleId] = array(
'article' => $article,
'fname' => $firstAuthor->getFirstName(),
'mname' => $firstAuthor->getMiddleName(),
'lname' => $firstAuthor->getLastName(),
'views' => $count
);
And I add the “{$articleInfo.authors} et al. ” code into the block file at (/public_html/ojs-2.4.7-1/plugins/blocks/mostPopularArticles/block.tpl):
<div class="block" id="sidebarNavigation">
<span class="blockTitle">{translate key="plugins.blocks.popularArticles.displayName"}</span>
{foreach from=$popularArticles item=articleInfo}
{assign var=iterator value=$articleInfo.article}
»<a href="{url page="article" op="view" path=$iterator->getArticleId()}">{$iterator->getArticleTitle()|escape}</a><br />
<span><em>{$articleInfo.fname[0]}.{if !empty($articleInfo.mname)} {$articleInfo.mname[0]|escape}.{/if} {$articleInfo.lname} et al.</em></span><br/>
<strong>{$articleInfo.views} {translate key="plugins.blocks.popularArticles.viewsSince"}: {$iterator->getDatePublished()|date_format:$dateFormatShort}</strong><br /><br />
{/foreach}
</div>
It works perfectly, enjoy it
1 Like
Hi @ihlasnobatovich ,
Excellent – thanks for writing this up. Just a note: it’s a good idea to use the Smarty escape
modifier liberally on things like {$articleInfo.lname}
, which are user-supplied and maybe not trustworthy. For example, that would be {$articleInfo.lname|escape}
.
Regards,
Alec Smecher
Public Knowledge Project Team
1 Like
Hi @asmecher ,
I improved the codes further. The was “et al.” problem in previous code. Now, I introduced a $ext variable that counts number of authors, and if it is more than 1 it adds “et al.” right after the first authors fullname.
(/public_html/ojs-2.4.7-1/plugins/blocks/mostPopularArticles/MostPopularArticlesDAO.inc.php)
$authors = $article->getAuthors();
if (count($authors) > 1) {
$ext='et al.';
}
else {
$ext='';
}
$firstAuthor =& $authors[0];
$articlesInfo[$articleId] = array(
'article' => $article,
'fname' => $firstAuthor->getFirstName(),
'mname' => $firstAuthor->getMiddleName(),
'lname' => $firstAuthor->getLastName(),
'ext' => $ext,
'views' => $count
);
And here is the modified block.tpl file:
<div class="block" id="sidebarNavigation">
<span class="blockTitle">{translate key="plugins.blocks.popularArticles.displayName"}</span>
{foreach from=$popularArticles item=articleInfo}
{assign var=iterator value=$articleInfo.article}
» <a href="{url page="article" op="view" path=$iterator->getArticleId()}">{$iterator->getArticleTitle()|escape}</a><br />
<span><em>{$articleInfo.fname[0]|escape}.{if !empty($articleInfo.mname)} {$articleInfo.mname[0]|escape}.{/if} {$articleInfo.lname|escape} {$articleInfo.ext}</em></span><br/>
<strong>{$articleInfo.views} {translate key="plugins.blocks.popularArticles.viewsSince"}: {$iterator->getDatePublished()|date_format:$dateFormatShort}</strong><br /><br />
{/foreach}
</div>
Enjoy it.
2 Likes
BMIJ
January 7, 2017, 9:50pm
5
Hi ihlasnobatovich,
May you share the whole modified plugin’s file? I am looking for most popular articles plugin that works in OJS 2.4.8.1.
Thanks already now.
1 Like
Is this available for OJS 3.0.2?
1 Like
can we make it? It is kind of need.
1 Like