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?

@eddoff

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>
                                           <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}
                                           {/foreach}
                                          </div>
                                   </div>
                           {/if}
                   </div>

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);
           $categories_array=$categories_array->toArray();
           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
Daniela

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.
oldgregg
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”? DefaultManuscriptChildThemePlugin.inc.php 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
Daniela

We’re using version 3.1.2.4. But so far I can’t solve the problem…
If I paste your code into DefaultManuscriptChildThemePlugin.inc.php, I get this warning:
image
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).
image

We more or less successfully updated to version 3.3.0-17 and I’m very impressed by the current plugin implementation. This is how it now looks in our case (I modified the Browse Block a little):

Awesome! Exactly what I wrote/asked! Great job, @NateWr and the whole team! :star_struck:

However, there is an unpleasant point that I consider necessary to note for developers. When I artificially change the address bar (https://biocomm.spbu.ru/catalog/category/ or https://biocomm.spbu.ru/catalog/), I get a 404 error. So, no handler is used for categories URLs.
On the contrary, if you try to cut off, for example, https://biocomm.spbu.ru/information/ (instead of https://biocomm.spbu.ru/information/readers), then this situation is correctly handled by a redirect to the main page. I think similar processing needs to be implemented for categories URLs.