Keyword

Premium items displaying in category for unregistered

  • eugen
  • eugen's Avatar Topic Author
  • Offline
  • Junior Member
More
7 months 1 week ago #181632 by eugen
Hello. I'm going to create premium access to some articles in the K2 component. I already have a special component for this. I created a group with special access. I started publishing articles in this way. But these articles are not displayed in the category for unregistered visitors. This means that an unregistered visitor does not know that there are special articles here and does not realize that he needs to register. Please Tell me how to configure the component so that the article with the access level "For registered or premium access" is displayed in the category, but after clicking on it, the visitor goes to registration page. Thank you!

Please Log in or Create an account to join the conversation.

More
6 months 1 week ago #181680 by William Wyatt
Replied by William Wyatt on topic Premium items displaying in category for unregistered
To configure the K2 component in Joomla so that articles with a specific access level are visible to all users but only accessible to registered or premium users, you can follow these steps. This involves showing a teaser or placeholder for the restricted content to all users and redirecting them to a registration or login page if they attempt to access the full content.

Please Log in or Create an account to join the conversation.

  • eugen
  • eugen's Avatar Topic Author
  • Offline
  • Junior Member
More
6 months 1 week ago #181681 by eugen
What steps do You mean?

Please Log in or Create an account to join the conversation.

More
6 months 1 week ago - 6 months 1 week ago #181683 by JoomlaWorks
Since this feature can be implemented in many ways, there was never a single way baked into K2 for it.

The simplest way (to me) is through the template overrides and most specifically in the item.php override. There, at the very top you can add a check if the category of the item is the "locked" one combined with a user login check. In pseudo code that would be:

if (category is this && user is not logged in) {
display a message and link to login
} else {
(rest of item.php)
}

OR in (untested) code:
$lockedCategories = [2,5,12]; // IDs of locked categories here
$user = JFactory::getUser();
if (in_array($this->item->category->id, $lockedCategories) && $user->guest) {
    // Display login message
    echo JText::_('JLOGIN_FORM_YOU_MUST_LOGIN');
    echo '<a href="' . JRoute::_('index.php?option=com_users&view=login') . '">' . JText::_('JLOGIN') . '</a>';
} else {
    //rest of item.php goes here
}

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 6 months 1 week ago by JoomlaWorks.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum