Jump to content

Display announcements on page outside client area


Recommended Posts

I am doing away with my current site which is built on Wordpress and combining the content of that site, an external invoicing program which runs on a sub-domain, and my reseller hosting business all into WHMCS using a paid theme from WHMCS Themes. (Great theme, by the way.)

The only hurdle left is to get the announcements to display on a new WHMCS page called Blog. I know that I could just make the announcements page do double duty by adding it the menu with the anchor text saying "Blog" instead of Announcements. But I want the announcements left in the client area and also display separately on a "blog" page by itself.

I added four dummy announcements for testing purposes and set them all to "published." They display without issue on the Announcements page. They display on the home page when I set the template to Six. They display on the homepage in the theme I bought if I add the code from the Six homepage .tpl to my current homepage.tpl.

On the blog page I want to display just the announcements without the client area navigation boxes on the left. The theme page that I am using for the blog has a right sidebar menu instead. I created a new page (.php & .tpl) called blog.tpl. I have tried inserting the code from the homepage.tpl that displays the announcements into the blog page. I have tried inserting the code from the announcements.tpl into the blog page. In both cases, I get a blue box with the words "No announcement to display."

I tried using the following {include} in my blog.tpl file. In that case the entire body of the page disappeared, leaving just the header and footer.

{include file='templates/BoxChat/announcements.tpl'}

I would appreciate any guidance anyone can offer.

Link to comment
Share on other sites

41 minutes ago, bookman53 said:

On the blog page I want to display just the announcements without the client area navigation boxes on the left. The theme page that I am using for the blog has a right sidebar menu instead. I created a new page (.php & .tpl) called blog.tpl. I have tried inserting the code from the homepage.tpl that displays the announcements into the blog page. I have tried inserting the code from the announcements.tpl into the blog page. In both cases, I get a blue box with the words "No announcement to display."

aah that won't work - because it's not the template that creates the underlying arrays, the template code is just used to display the arrays passed to it by WHMCS.

41 minutes ago, bookman53 said:

I would appreciate any guidance anyone can offer.

you've got three options:-

  1. create the announcements array in your .php file - that's going to be a query to the database... see the creating pages docs.
  2. create the announcements array in a hook - again, that's a query to the database.
  3. use the announcements rss feed.

ideally, you should do (1), but i'm on my way out, so i'll quickly give you a link to (2) and that shows how to pass more than x announcements to the homepage - now in your case, change ClientAreaPageHome to ClientAreaPage and you'll be able to use it on your custom page.

untested, but using that hook, you should be able to use the homepage.tpl code to output the announcements on your custom page.

Link to comment
Share on other sites

That almost got me to my goal. Using the hook in the #2 example you gave, and changing ClientAreaPageHome to ClientAreaPage I was able to get the announcements to display on my blog page.

The thing that remains is that the blog page initially displays the excerpts as it should. But when I click to read the entire announcement, it returns me to the announcements page to read the entire article or announcement. Is there a way to cause them to open in the blog page where the excerpts are instead of sending me to the announcements page?

Thanks! brian!

Link to comment
Share on other sites

15 hours ago, bookman53 said:

The thing that remains is that the blog page initially displays the excerpts as it should. But when I click to read the entire announcement, it returns me to the announcements page to read the entire article or announcement. Is there a way to cause them to open in the blog page where the excerpts are instead of sending me to the announcements page?

oh this is a Pandora's box that you really might find is better left closed. ⚠️

17 hours ago, bookman53 said:

The only hurdle left is to get the announcements to display on a new WHMCS page called Blog. I know that I could just make the announcements page do double duty by adding it the menu with the anchor text saying "Blog" instead of Announcements. But I want the announcements left in the client area and also display separately on a "blog" page by itself.

displaying them is easy (as you have found) - but it never occurred to  me yesterday that you were wanting to make the links follow through and still pretend to be in the blog.

the problem here is that the announcements page does a lot of the work of generating the .html pages for each announcement - that's certainly going to be a 3-digit number of lines of code as compared to the 10 or so you need to create a custom page normally... I daresay it could be done with considerable effort, but there is a reason why the three blog modules in Marketplace aren't free. ☺️

in terms of output, what can you live with ?  there is nothing to stop you posting every announcement on the blog page, even entire articles - e.g if you changed your blog.tpl template to...

{foreach $announcements as $announcement}
	<div class="announcement-single">
		<h3>
			<span class="label label-default">{$carbon->translatePassedToFormat($announcement.rawDate, 'M jS')}</span>
			{$announcement.title}
		</h3>
		<blockquote>
			<p>{$announcement.text}</p>
		</blockquote>
	</div>
{/foreach}

... that would post the entire content of the articles and not just a summary... then it's just a case of playing with the layout, formatting, styling etc to suit your site design... e.g using collapsible accordion style output (to save space) or whatever... I might be inclined to use the code from the announcements template, though that would then require additional changes to the hook.

note that the hook is currently limited to taking only 5 articles, but you could remove that limitation and get them all if you wanted to.

also, that hook will need an if statement to ensure that it only works on the blog page and not on every page in the client area...

<?php

# Get Announcements On Blog Page Hook
# Written by brian!

use WHMCS\Database\Capsule;

function announcements_hook($vars)
{
	if ($vars['filename'] == "blog") {
		$announce = Capsule::table('tblannouncements')->where('published', '1')->select('id','date as rawDate','title','announcement as text')->orderBy('date','desc')->get();
		$announcements = json_decode(json_encode($announce),true);
		return array("announcements" => $announcements);
	}
}
add_hook("ClientAreaPage", 1, "announcements_hook");

if your filename isn't called "blog.php", then change "blog" in the hook to whatever the custom file is called (without the .php extension).

there will be other potential minefields with this, one being if you have articles in multiple languages, but that bridge can be left and only crossed if you need to cross it.

Link to comment
Share on other sites

Taking your ideas into consideration, I think I might be better off just using the announcements page, rename the title in the theme and the anchor text in the menu to "blog". I liked what I saw when I implemented the hook you pointed me to. The page of excerpts was exactly what I'd been trying to accomplish. But not being familiar enough with the way WHMCS works behind the scenes, I just assumed the excerpts would open in the same page. I'm concerned about the eventual page load size if I were to display the full text from each announcement. At first, there wouldn't be much there. But eventually, the page could grow so long as to become crazy to deal with. Mobile users might wear out their thumbs trying to scroll through the entire page. 🙂

I looked at a couple of the blog modules available in the marketplace, but I can't imagine they would be any easier to incorporate into my existing theme, since they all have their own templating system.

If I understand you correctly, if I want the excerpts to open on the same page, I should perhaps just stay with the announcements page itself. Is that correct?

Link to comment
Share on other sites

17 hours ago, bookman53 said:

Taking your ideas into consideration, I think I might be better off just using the announcements page, rename the title in the theme and the anchor text in the menu to "blog".

and Pandora's box has been closed. ☢️

17 hours ago, bookman53 said:

The page of excerpts was exactly what I'd been trying to accomplish. But not being familiar enough with the way WHMCS works behind the scenes, I just assumed the excerpts would open in the same page.

sadly not - announcements.php opens a specific article into a faked (in the sense that it doesn't physically exist on the server) html page.

20 hours ago, bookman53 said:

I'm concerned about the eventual page load size if I were to display the full text from each announcement. At first, there wouldn't be much there. But eventually, the page could grow so long as to become crazy to deal with.

yeah that thought occurred to me afterwards as well.

20 hours ago, bookman53 said:

I looked at a couple of the blog modules available in the marketplace, but I can't imagine they would be any easier to incorporate into my existing theme, since they all have their own templating system.

plus creating a duplication of content - e.g you would have to add a new post to both the blog and announcements.

21 hours ago, bookman53 said:

If I understand you correctly, if I want the excerpts to open on the same page, I should perhaps just stay with the announcements page itself. Is that correct?

that's the simplest way - it prevents reinventing of the wheel... but is your reluctance to do this based on your client area design not matching your main site ??

it is possible to have a custom page behave like the announcements page and initially just show a x character summary of the articles (the full content of the article is NOT included in the results), but when one is clicked, to open that article up in full on the same page - there is NO redirection to announcements.php, everything is shown in the blog.php file (check the browser URL shown in the screenshot).

vyqlWh7.gif

I might add pagination to this (as the announcements page paginates after 10 articles) and polish it up a bit - it's an updated version of the above hook and a tweak to the blog.tpl template... no changes to the php file.

Link to comment
Share on other sites

brian! Yes, that's exactly what I'd like to accomplish. I don't intend announcements to be exclusively available to my clients. My intent from the beginning has actually been to have the announcements display publically on my blog page and act exactly as your screenshot shows. I don't want the announcements (masquerading as blog posts) to have the client area navigation boxes. The .tpl that I'm using for the blog page is the same as the legal pages in my bought theme. It has a right sidebar navigation which allows me to control which links are included. And yes, pagination after 10 article excerpts would be grand.

Would doing it this way cause WHMCS to always display announcements via my blog page only no matter where they were linked from, or would it also display them on the default client area page? That would be duplicate content if it happened that way.

Thanks.

Link to comment
Share on other sites

21 hours ago, bookman53 said:

brian! Yes, that's exactly what I'd like to accomplish.

I thought it might be. 🙂

21 hours ago, bookman53 said:

I don't intend announcements to be exclusively available to my clients.

it's worth noting that everyone can access your announcements page by default (if they know where it is) - clients, non-clients... anyone.

as an example, here's WHMCS own announcements page - they obviously no longer use it (not for the last 8 years), but you don't need to log in to see it... anyone can find it via Google.

https://www.whmcs.com/members/announcements.php

k9vZAFu.png

if your client area is not like your main site in appearance, then perhaps that is a reason not to use announcements.

21 hours ago, bookman53 said:

My intent from the beginning has actually been to have the announcements display publicly on my blog page and act exactly as your screenshot shows. I don't want the announcements (masquerading as blog posts) to have the client area navigation boxes.

the two sidebars on the left hand side? you can remove them with a hook and the remaining content will use the deserted space.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
	if (!is_null($primarySidebar->getChild('Announcements Months'))) {
		$primarySidebar->removeChild('Announcements Months');
	}
});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
	GLOBAL $smarty;
	$templatefile = $smarty->getVariable('templatefile');
	if (!is_null($secondarySidebar->getChild('Support')) && $templatefile == 'announcements') {
		$secondarySidebar->removeChild('Support');
	}
});

pupCvE3.png

the hook should work on Boxchat without issue and will remove the Announcement Months sidebar (first sidebar) and the Support sidebar (lower one) from the Announcements page only.

21 hours ago, bookman53 said:

The .tpl that I'm using for the blog page is the same as the legal pages in my bought theme. It has a right sidebar navigation which allows me to control which links are included.

i'm assuming that there is a .php and.tpl for a custom page with that theme?

21 hours ago, bookman53 said:

Would doing it this way cause WHMCS to always display announcements via my blog page only no matter where they were linked from, or would it also display them on the default client area page?

as currently written, both pages (announcements and blog) would display the same content.

21 hours ago, bookman53 said:

That would be duplicate content if it happened that way.

indeed... but I don't know if you think that is a good thing or not! 🙂

possibly, with those two sidebars now removed from the announcements page, it might be a simpler option to rename it to Blog and use that.

however, if not, you can be in control of what content is displayed on these pages... e.g if you are saying that you only want specific blog posts/announcements to appear on the blog page, and you don't want those blog posts to appear in announcements, then that's doable... in fact, I can think of ways where you could create announcement posts for multiple different blogs and use the hook (or the php file) to determine what is shown on which blog page and/or announcements page... but let's not overcomplicate the issue if all you wanted to do is remove those two sidebars! 😀

Link to comment
Share on other sites

Yes, BoxChat allows me to add my own pages with .php and .tpl. In the case of the blog page, I basically just duplicated one of the legal pages and replaced the content with announcements code.

In the most basic terms, I just have in mind using announcements as my blog. I don't even need to use categories as one might in WordPress. I won't be posting there on a set schedule - just when something comes to mind that I think my clients or potential clients might benefit from.

From here, I'd like to have the announcements display (and open to full posts) as in the demo screenshot you posted a couple replies back. I would like the primary and secondary menu boxes gone from the blog page display, which I believe the hook you wrote in your last post will accomplish. I want to leave the right sidebar menu as I have it now. That should be no problem since I am just embedding the announcements code inside one div.

As for duplicate content, one day I hear it's no problem. The next day, it's a big problem, back and forth. I personally had rather not have the same posts duplicated on one website. If nothing else, it could be confusing to the reader.

Thanks.

Link to comment
Share on other sites

On 5/1/2020 at 9:08 AM, brian! said:

...the hook should work on Boxchat without issue and will remove the Announcement Months sidebar (first sidebar) and the Support sidebar (lower one) from the Announcements page only.

i'm assuming that there is a .php and.tpl for a custom page with that theme?

as currently written, both pages (announcements and blog) would display the same content.

indeed... but I don't know if you think that is a good thing or not! 🙂

possibly, with those two sidebars now removed from the announcements page, it might be a simpler option to rename it to Blog and use that.

however, if not, you can be in control of what content is displayed on these pages... e.g if you are saying that you only want specific blog posts/announcements to appear on the blog page, and you don't want those blog posts to appear in announcements, then that's doable... in fact, I can think of ways where you could create announcement posts for multiple different blogs and use the hook (or the php file) to determine what is shown on which blog page and/or announcements page... but let's not overcomplicate the issue if all you wanted to do is remove those two sidebars! 😀

brian!, I would be a very happy camper if I could have either of these scenarios happen, whichever is easier:

1) Cause the entire announcement/blog post to open on the same page as the excerpts as you demonstrated in your reply last Thursday, but to do so on the blog page. That, using the hook you wrote would allow me to keep the right side bar which is more easily customizable (at least for me), while also doing away with the two left sidebars.

2) Keep the announcements page, changing the h1 title and the menu link anchor text to something other than announcements. Do away with the left side menus as with the hook you wrote, but also include the right side navigation that I currently have on my almost-working blog page.

Going with the number 2 option would do away with any possible duplicate content issues, but I'm not sure what difficulty it would raise to add the right navigation.

I suppose there is a possibility of using a redirect of some sort, but at just 66 years of age, I'm not so sure I'm old enough to deal with the complications that might bring up. 😬

Thanks for all the help you've given thus far.

Link to comment
Share on other sites

brian!

I never got the blog page worked out so that it would load the entire articles there instead of in the client area. So, to keep from complicating this announcement/blog project anymore than necessary I've decided to just run with the idea of keeping the announcements page, changing the menu anchor text to read "Blog," but load the announcements page instead of the blog page. I do have two other smaller issues, but I'll raise them in their own threads.

Thank you for your help on this. You were very helpful.

Edited by bookman53
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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