User specific Article info display setting Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Post Reply
User avatar
Madcustard
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Mar 22, 2023 12:29 am

User specific Article info display setting

Post by Madcustard » Wed Mar 22, 2023 12:44 am

Hi There

' Removing author name, creation date or update date from an article '

Code: Select all

https://docs.joomla.org/Removing_author_name,_creation_date_or_update_date_from_all_articles
is helpful, however I would like to remove this only for - super users - or - administration -
created posts , is there a way I can make hide these fields from the public + registed users only?
below the - administraton - (& or superusers) level ??

any tips would be greatly appreciated 8)
Last edited by toivo on Wed Mar 22, 2023 6:50 am, edited 1 time in total.
Reason: mod note: moved from 4.x General Questions

User avatar
Madcustard
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Mar 22, 2023 12:29 am

Re: User specific Article info display setting

Post by Madcustard » Wed Mar 22, 2023 2:51 am

I guess even if I could hide this Article info form just from the
overall view of the Home page / index ?
then that would be helpful enough if anyone has suggestions

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 16122
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: User specific Article info display setting

Post by toivo » Wed Mar 22, 2023 7:15 am

An unusual requirement, if I may say so, but it can be done in a template override of the article view. Go to System - Templates - Site Templates and select your front end template, for example Cassiopeia Details and Files. Go to the tab Create Overrides and select Components - com_content. The override of the Article view of the Content component is now available as templates/cassiopeia/html/com_content/article/default.php.

The file default.php can now be modified without the changes getting overwritten in the next Joomla update. In the future the code may have to be refactored, depending on possible changes to the code of the article view.

The additions to default.php, shown below, check first the user groups of the author of the article and also the user group of the current user. If the article was created by a user in the Administrator or Super Users group, the article info will be hidden from all front end visitors and logged-in users. If the article info needs to be displayed to users in the Administrator and Super Users groups at the front end, uncomment the line marked 'optional' and comment out the previous line.

Insert the following lines after line 30 of the default.php override file in Joomla 4.2.9:

Code: Select all

// 20230322 author and current user
$Administrator	= 7;
$SuperUsers	= 8;
$author		= Factory::getUser($this->item->created_by, 0);
// hide article info if author belongs to Administrator or Super Users groups
$hideInfo	= in_array($Administrator, $author->groups) || in_array($SuperUsers, $author->groups); 
// show article info if user belongs to Administrator or Super Users groups
$showInfo	= in_array($Administrator, $user->groups) || in_array($SuperUsers, $user->groups); 
// 20230322 end
Insert the following lines after the original line 51, as soon as the variable $useDefList has been set:

Code: Select all

	<?php 
	// 20230322 start
	$useDefList	= $useDefList && !$hideInfo; // show info unless created by Administrators or Super Users	
	// $useDefList	= (($useDefList && !$hideInfo) || $showInfo); // optional: show info to Administrator&Super User	
	// 20230322 end
	?>
Toivo Talikka, Global Moderator

User avatar
Madcustard
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Mar 22, 2023 12:29 am

Re: User specific Article info display setting

Post by Madcustard » Mon Mar 27, 2023 9:39 pm

Thank you Toivo Talikka ,
Yes an unusual request, which is why I had trouble finding a solution,
the Joomla4 overides are great (as well as easy to make a copy to avoid update issues)
but now there sounds like an answer to the problem, so I thank you
This should do the trick - I will provide an update when I've successfully implemented it,
also now there is a reference should someone else need to find the answer
to an unusual request :)

User avatar
Madcustard
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Mar 22, 2023 12:29 am

Re: User specific Article info display setting - UPDATE

Post by Madcustard » Mon Mar 27, 2023 10:19 pm

Again Toivo Talikka
Thank you ,Its working perfectly as intended 8)
now as Admin I can write posts on behalf of the site
without needing the backlinks & details needed for regular registered users
(If I needed too I have the optional code, however I can also make a 'registered'
level account if needed) - I really appreciate the help you gave me :)
(also I have a great template from Github, but your instructions were easy to follow)

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 16122
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: User specific Article info display setting

Post by toivo » Mon Mar 27, 2023 10:36 pm

Good to hear that it works!

As an summary, the modified code stops the whole info block from being displayed at the article view level. It would not be possible to pick individual details like the date or the author the same way because the details of the info block are rendered deep down inside the Joomla core, rather than in the article view.
Toivo Talikka, Global Moderator

User avatar
Madcustard
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Mar 22, 2023 12:29 am

Re: User specific Article info display setting

Post by Madcustard » Sun Apr 30, 2023 1:01 pm

Yes, after getting more Familiar with Joomla 4 The override system is great,
Also, I've figured out that I needed to manually switch alot of things onto Hide
on the Article Options as despite the global settings saying hide I finally realised
that I still needed to change from global to hide (despite hide being default)
& which had made all the difference too.

(I left the override code in for now as I'm sure it's helping too
& I'll know in the future that I can remove it should it become an issue,
but so far I get nice clean detailed free Articles that do not overwhelm the users with unnecessary links,
(unnecessary at that point for the user as I can always make a new menu item)

so I feel this solution has given me more control,
Joomla 4 really is a powerful CMS & is a matter of getting over the learning curve
by making mistakes + learning from them.

I also cannot recommend enough to anyone about how important making backups are!
Thanks again, your Answers to other people with other similar questions (I've had) have been gold!

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 16122
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: User specific Article info display setting

Post by toivo » Sun Apr 30, 2023 10:05 pm

@Madcustard, glad to see progress made in leaps and bounds!

Still about the article info block, which is not rendered "deep down inside the Joomla core", as I thought in the above reply, but in fact implemented through layouts, and layouts can of course be overridden. Here is a recent example and the info block: show modified_by-user.
Toivo Talikka, Global Moderator


Post Reply

Return to “Joomla! 4.x Coding”