Categories on article landing pages

Dear @Vitaliy and all others!

I have OJS 3.1.2-1, and oldGregg theme, and I want to show the categories chosen for an article (with link to each category) on the article landing page. Is that possible to implement? Which code should I add to the tpl-file?


We dont’t use the oldGregg theme, but we have added the categories to our own theme in the article_details.tpl (if you have only one language in your journal you could make this a bit simpler - we’ve also linked the category names to the category page):

                    {assign var=articleLocale value=$article->getLocale()}
                              {if $categories}
                                   <div class="sub_item">
                                           <div class="label">
                                                   {translate key="navigation.categories"}
                                           <div class="value">
                                           {foreach name=categories from=$categories item=category}
                                                   {if $linked}<a href="{url router=$smarty.const.ROUTE_PAGE page="catalog" op="category" path=$category.path|escape}">{/if}{if !empty($category.titles[$currentLocale])}{$category.titles[$currentLocale]|escape}{else}{$category.titles[$articleLocale]|escape}{/if}{if $linked}</a>{/if}{if !$smarty.foreach.categories.last}; {/if}

But to get this to work we first needed to send the metadata to the template. So we added a function in the main PHP file of your theme to add this (and other metadata) to our articles. The code we used in the function is:

            $templateMgr = TemplateManager::getManager($request);
           $article =$args[2];
           $articleId = $article->getId();
           $request = $this->getRequest();
           $journal = $request->getJournal();
           $journalid = $journal->getId();
           if (isset($journal)) {
                           $locales = $journal->getSupportedSubmissionLocales();
                   } else {
                           $site = $request->getSite();
                           $locales = $site->getSupportedSubmissionLocales();
           $dao = Application::getSubmissionDAO();
           $categories_array = $dao->getCategories($articleId);
           foreach($categories_array as $category) {
              $category_id = $category->_data['id'];
              $category_titles = $category->_data['title'];
              $category_path = $category->_data['path'];
              $categories[$category_id]['titles'] = $category_titles;
              $categories[$category_id]['path'] = $category_path;
           $templateMgr->assign('categories', $categories);

Kind regards

Hi @eddoff,

Yes, it’s already implemented for the Old Gregg theme but isn’t yet released. As well as most viewed articles alongside with recent ones.
The next version is 90% ready and lies here: GitHub - Vitaliy-1/oldGregg at dev
As you can see it looks different (hope better).

Great @Vitaliy!
I look forward to the new version! Since we have made our own child theme, I hope we can merge our changes so that they are in line with the new version.

Thank you @UBWolf, I will try that!

Dear Daniela, I’m trying to implement your solution for our Manuscript Child Theme. Could you, please, clarify what is meant by “the main PHP file of your theme”? or some other?

Dear @rkhalikov,

yes, that should be the one. Please be aware that the code I posted cannot be used for OJS Version 3.2 and higher.

Kind regards

We’re using version But so far I can’t solve the problem…
If I paste your code into, I get this warning:
If this code is inserted just in the beginning of the file, I get a 500 error.

You need to put the code in a function.
But I would recommend to only change the theme files if you have PHP knowledge.

OK, I do not have the necessary PHP knowledge. Apologize for disturbing you.

Hope @NateWr can implement categories displaying (for example, in the block {* Issue article appears in *}) in one of the next theme releases.

This is filed in Add Category to article page in OJS · Issue #4991 · pkp/pkp-lib · GitHub but not yet scheduled to be implemented. I’ve added a note there to indicate the interest expressed here.

Thanks! We did not consider this question so deeply, in our practice the categories are in any case appointed by the editors, and not the authors during submission.
However it would be very useful to have on article page something like this (Paleontology is one of the categories).