Jump to content

Display more than 3 latest announcements on Client Area Home


gbotica

Recommended Posts

The Announcements panel on the client area homepage shows the last 3 announcements - is there anyway (preferably, without completely rewriting the clientareahome.tpl) to increase this?

do you mean homepage.tpl rather than clientareahome.tpl - or are you thinking specifically of the "Recent News" homepage panel ??

 

either way, the answer is basically the same - they're both limited to a maximum of 3 articles (it's not the template, it's the array hard-coded by WHMCS) - to get around either would need an action hook.

 

in the case of homepage.tpl, you'd just need a hook that queries the db and recreates the $announcements array with x number of articles (x being a number chosen by you); for clientareahome, you'd need a similar query but you would output it via a homepagepanel hook.

Link to comment
Share on other sites

so it's a homepage panel or are you using some other method to output the array ?

 

I'm just using the standard client area homepage, so yes - the homepage panel. I like to keep my modifications to minimum, where ever possible, so will just leave this as-is for now. It's a shame there isn't a setting or config variable to be able to just change the number of items displayed.

 

Thanks again for your help.

Link to comment
Share on other sites

I'm just using the standard client area homepage, so yes - the homepage panel. I like to keep my modifications to minimum, where ever possible, so will just leave this as-is for now. It's a shame there isn't a setting or config variable to be able to just change the number of items displayed.

I suspect that WHMCS are far too busy with their current obsession of developing WHMCS MarketConnect to worry about such things... in fact, even before that, I think it wouldn't be on their radar.

 

why they didn't think to put these default homepage panels as public hooks where we could just edit the code is beyond me. :twisted:

 

to change the output from 3 to x, you'd effectively have to rewrite the panel from scratch via an action hook - that's not technically difficult to do as you're just querying one table and perhaps tweaking the date output - but if they'd left them as accessible hooks, it's just a minor value change in the query. *sighs*

 

i've bookmarked the thread and will come back and write the hook at some point in the future for others - it's one of those minor things that will take me less than 10 minutes to do... the trick is finding that spare 10 minutes! :)

Link to comment
Share on other sites

  • 10 months later...
On 2/27/2018 at 14:10, Cowboy said:

On the home page for me. So at the moment I only see the two most recent announcements. I'd like to show maybe 5 or possibly more. 

then you have two problems to work around...

  1. the $announcements array, used in the homepage, only contains a maximum of 3 announcements.
  2. the homepage.tpl template is hard-coded to only show 2 announcements.

so to get around the first issue, you need to create a hook to query the database and get the last x announcements - in the example below, i'm going to limit it to 5, but you could change that to any number, or remove it to get all announcements... so in /includes/hooks create a new .php file, call it homeannounce.php (or anything you like) and paste the code below into it...

<?php

# Get More Announcements on Homepage
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

function homepage_announcements_hook($vars) {

	$announce = Capsule::table('tblannouncements')
				->where('published','<>','0')
				->where('published','<>','')
				->select('id','date as rawDate','title','announcement as text')
				->orderBy('date','desc')
				->limit(5)
				->get();
				
	$encodedata = json_encode($announce);
	$decodedata = json_decode($encodedata, true);
	
	foreach ($decodedata as $index => $option){
		$decodedata[$index]['urlfriendlytitle'] = getModRewriteFriendlyString($decodedata[$index]['title']);
		$decodedata[$index]['summary'] = mb_strimwidth($decodedata[$index]['text'], 0, 350, "...");
	}
	
	return array("announcements" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "homepage_announcements_hook");
?>

that will now give you an announcements array containing x number of posts - so now we just need to edit the homepage.tpl template and get it to show more announcements...

the limit is imposed by the following line ~16

{if $announcement@index < 2}

if you wanted to show all announcements, and you had tweaked the above hook to get them all, you could remove the above line entirely (along with its corresponding /if too)... or use the following code to show all the announcements in the array (as either defined by the limit value in the hook, or the entire array if no limit is specified)...

{if $announcement@index < $announcements|@count}

when updating WHMCS, remember that it may overwrite this change to the template (but not the hook) - so keep a note about replacing the line after an update... otherwise, you'll be back to just showing 2 announcements again! :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated