1
votes

I have an article category in my Joomla website in which all its articles are meant to be seen only by registered users. When I set a module to list them on my home page, they only show up when the user is logged in. However, I would like all the articles of this category to be listed even if the user hasn't logged in, and when he/she clicks on the links he'll be prompted to introduce his/her login data. ¿How can this be made?

1
Hello. What exactly module are you using to show articles list? - Andrei Konstantinov

1 Answers

1
votes

In order for this to work, you are going to have to create a template override for the article pages. Since you want the home page module to display the article for all users, the article will need to be set to public, otherwise they won't show.

Then you will need to override this file - components/com_content/views/article/tmpl/default.php

Make a copy and place it in here - templates/YOUR TEMPLATE/html/com_content/article/default.php

If you want to protect all of the content leave the override file name as default.php. If you only need to protect certain categories, then use a different file name, then in the Category Advance Options, select the file you have uploaded fron the Alternate Layout dropdown.

In the override, you will need to add this code:

<?php $user =& JFactory::getUser();
if($user->id) : ?>
CONTENT YOU WANT PROTECTED HERE
<?php else: ?>
CONTENT TO DISPLAY IF USER IS NOT LOGGED IN
<?php endif; ?>

This will allow you to leave your articles as public, but hide the content if the user is not logged in.