Jump to content

Announcements on index page


SoBeIt

Recommended Posts

you should put {php} and {/php} arround the code in your homepage.tpl file

 

the complete source would look like:

{php}

$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3";

$result = mysql_query($query);

while ($data = mysql_fetch_array($result)) {

$id = $data["id"];

$date = $data["date"];

$title = $data["title"];

$announcement = $data["announcement"];

$date = fromMySQLDate($date);

echo("<p><font color=#cccccc>$date</font> - <b>$title</b><br>$announcement</p>");

}

{/php}

 

To truncate your messages have a close look at http://www.the-art-of-web.com/php/truncate/

Link to comment
Share on other sites

<?php
include("PATH/configuration.php");
include("PATH/includes/functions.php");
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 5";
$result=mysql_query($query);
while($data = mysql_fetch_array($result)) {
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);


echo("News $date<a  href=http://www.LINKSITE.xx/announcements.php?id=$id target=blank>$title</a>");


}
?>

 

 

i modify With link.....and i limit first 5 news

Link to comment
Share on other sites

Great, thank you, it works fine now :)

 

I thought the truncate feature would only require an extra line in the code or something simple, looking at that URL I think I'll just have to keep my announcements short!

Link to comment
Share on other sites

<?php
include("PATH/configuration.php");
include("PATH/includes/functions.php");
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 5";
$result=mysql_query($query);
while($data = mysql_fetch_array($result)) {
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);


echo("News $date<a  href=http://www.LINKSITE.xx/announcements.php?id=$id target=blank>$title</a>");


}
?>

 

 

i modify With link.....and i limit first 5 news

 

I am confused how that can work -- in the wiki article the 2nd line is supposed to be:

 

include("support/dbconnect.php");

 

Why do you have configuration.php?

Link to comment
Share on other sites

When I add the script from the wiki to the front page of my website, this is what I get in the section where the announcements should appear:

 

Site error: the file /home/myaccount/public_html/whmcs/dbconnect.php requires the ionCube PHP Loader ioncube_loader_lin_4.4.so to be installed by the site administrator.

 

I have a copy of php.ini in my public_html folder as well as a copy of ioncube_loader_lin_4.4.so. The very same code works if I put my php page inside my whmcs folder. Of course, I am adjusting all paths relatively as required. I just don't get it.

Link to comment
Share on other sites

Hi Apollo1,

 

had to tweak to get the code to work inside whmcs, below is what I use, error free.

 

<p><b><a href="announcements.php">Recent Announcements</a></b><br /></p>

 

 

{php}

$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,6";

$result = mysql_query($query);

while ($data = mysql_fetch_array($result)) {

$id = $data["id"];

$date = $data["date"];

$title = $data["title"];

$announcement = $data["announcement"];

$date = fromMySQLDate($date);

echo("<p><img src=\"images/clientarea/bullet2.gif\" align=\"middle\" alt=\"article\"/> <font color=\"#800000\"> $date</font><br/><b>$title</b></p>");

}

{/php}

 

 

the \ inside the echo escape the quotes that you need to be error free, which is a missing component to silverweb's code.

 

I've included code for a bullet icon. rename it to whatever you want, and change the location to wherever suits your setup.

 

As the announcement page are not individually viewed, i thought it better just to link the heading & take them to the whole page. Clients can scroll down to find the one they want.

 

Cheers

Link to comment
Share on other sites

  • 4 weeks later...
you should put {php} and {/php} arround the code in your homepage.tpl file

 

the complete source would look like:

 

 

To truncate your messages have a close look at http://www.the-art-of-web.com/php/truncate/

 

 

My hompage.tpl file looks nothing like that, so I am a bit leary of trying to add that code to it. Here is what I have in my hompage.tpl file:

 

<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>{$LANG.headertext}</td><td align="right">{if $showpresales}{$LANG.supportpresalesquestions}, <a href="contact.php">{$LANG.supportclickheretocontact}</a>.{/if}</td></tr></table>

<br />

<table width="100%" border="0" align="center" cellpadding="12" cellspacing="0" style="border: 1px solid #e0e0e0;">
<tr><td width="10%"><div align="center"><a href="clientarea.php"><img src="images/clientarea_big.gif" alt="{$LANG.clientareatitle}" /></a></div></td><td width="40%" style="padding-left:5px;"><a href="clientarea.php"><strong>{$LANG.clientareatitle}</strong></a><br />{$LANG.clientareadescription}</td><td width="10%" bgcolor="#EFF2F9"><div align="center"><a href="submitticket.php"><img src="images/submitticket_big.gif" alt="{$LANG.supportticketssubmitticket}" /></a></div></td><td width="40%" bgcolor="#EFF2F9" style="padding-left:5px;"><a href="submitticket.php"><strong>{$LANG.supportticketssubmitticket}</strong></a><br />{$LANG.submitticketdescription}</td></tr>
<tr><td width="10%" bgcolor="#EFF2F9"><div align="center"><a href="knowledgebase.php"><img src="images/knowledgebase_big.gif" alt="{$LANG.knowledgebasetitle}"/></a><a href="clientarea.php"></a></div></td><td width="40%" bgcolor="#EFF2F9" style="padding-left:5px;"><a href="knowledgebase.php"><strong>{$LANG.knowledgebasetitle}</strong></a><br />{$LANG.knowledgebasedescription}</td><td width="10%"><div align="center"><a href="supporttickets.php"><img src="images/supporttickets_big.gif" alt="{$LANG.supportticketspagetitle}" /></a></div></td><td width="40%" style="padding-left:5px;"><a href="supporttickets.php"><strong>{$LANG.supportticketspagetitle}</strong></a><br />{$LANG.viewticketsdescription}</td></tr>
<tr><td width="10%"><div align="center"><a href="announcements.php"><img src="images/announcements_big.gif" alt="{$LANG.announcementstitle}" /></a></div></td><td width="40%" style="padding-left:5px;"><a href="announcements.php"><strong>{$LANG.announcementstitle}</strong></a><br />{$LANG.announcementsdescription}</td><td width="10%" bgcolor="#EFF2F9"><div align="center"><a href="cart.php"><img src="images/order_big.gif" alt="{$LANG.ordertitle}" /></a></div></td><td width="40%" bgcolor="#EFF2F9" style="padding-left:5px;"><a href="cart.php"><strong>{$LANG.ordertitle}</strong></a><br />{$LANG.orderhomedescription}</td></tr>
<tr><td width="10%" bgcolor="#EFF2F9"><div align="center"><a href="affiliates.php"><img src="images/affiliate_big.gif" alt="{$LANG.affiliatestitle}" /></a></div></td><td width="40%" bgcolor="#EFF2F9" style="padding-left:5px;"><a href="affiliates.php"><strong>{$LANG.affiliatestitle}</strong></a><br />{$LANG.affiliatesdescription}</td><td width="10%"><div align="center"><a href="downloads.php"><img src="images/downloads_big.gif" alt="{$LANG.downloadstitle}" /></a></div></td><td width="40%" style="padding-left:5px;"><a href="downloads.php"><strong>{$LANG.downloadstitle}</strong></a><br />{$LANG.downloadsdescription}</td></tr>
<tr><td width="10%"><div align="center"><a href="domainchecker.php"><img src="images/domains_big.gif" alt="{$LANG.domaintitle}" /></a></div></td><td width="40%" style="padding-left:5px;"><a href="domainchecker.php"><strong>{$LANG.domaintitle}</strong></a><br />{$LANG.availabilitydescription}</td><td width="10%" bgcolor="#EFF2F9"><div align="center"><a href="serverstatus.php"><img src="images/status_big.gif" alt="{$LANG.serverstatustitle}" /></a></div></td><td width="40%" bgcolor="#EFF2F9" style="padding-left:5px;"><a href="serverstatus.php"><strong>{$LANG.serverstatustitle}</strong></a><br />{$LANG.serverstatusdescription}</td></tr>
</table>
<br />

 

Where should I enter your code so that I can get the announcements to show up on the main page when a user logs in?

 

Thanks in advance!

Link to comment
Share on other sites

For us, since our billing is on a separate server than our main page I did the following.

 

Made an "announcements-remote.php" file in our BILLING server, and then used a PHP ECHO command to display on the page I wanted to display.

 

So here's what I have on my site pages:

 

<?php
echo file_get_contents("[url]http://billing.handsonwebhosting.com/announcements-remote.php[/url]");
?> 

 

And then in the "announcements-remote.php" file I have the following:

 

*** weird, it wouldn't let me paste the full code. I'll post in a following posting.

Link to comment
Share on other sites

<?
$x=1;
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
$text = substr($text,0,200);
$text = substr($text,0,strrpos($text,' '));
$text = $text." ... ";
return $text;
}
// format the date to mm/dd/yyyy
function formatdate($date) {
$year = substr ($date, 0, 4);
$month = substr ($date, 5, 2);
$day = substr ($date, 8, 2);
return $month.'/'.$day.'/'.$year;
}
// limit the number of announcements to return
$limit = 3;

require '/home/billing/public_html/configuration.php';
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);

$result = mysql_query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT ".$limit);
while($data = mysql_fetch_array ($result))
{
$id = $data['id'];
$title = $data['title'];
$date = $data['date'];
$announcement = truncate($data['announcement']);
$date = formatdate($date);
echo'<b>'.$date.' - '.$title.'</b><br>'.$announcement.' <a href="[url="http://billing.handsonwebhosting.com/announcements.php?id='.$id.'"><img"]http://billing.handsonwebhosting.com/announcements.php?id='.$id.'"><img[/url] src="[url]http://billing.handsonwebhosting.com/images/details.png[/url]" border="0" alt="more info" /></a>';
echo'<hr />';
$x=false;
}
if(!$x) echo '<p>Older News & announcements: < a href="http://billing.handsonwebhosting.com/announcements.php> view more </a></p>';if($x) echo '<p>There are no new announcements.</p>';
?> 

Link to comment
Share on other sites

wouldn't let me delete this posting.

 

Anyway, the above code is what we used on our site - maybe it'll be of some help to you in your issue.

 

Conor - there was one small bug in your code. The "no new announcements" isn't working right. I had to delete the line $x=false; and add the following line above the while statement.

 

if ($result < $limit) {$x=0;}

Link to comment
Share on other sites

<?php
include("clients/dbconnect.php");
include("clients/includes/functions.php");
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,5"; 
$result = mysql_query($query);
while ($data = mysql_fetch_array($result)) {
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);
 echo("<font color='#FF0000'>$date</font> - <b>$title</b> <br /> $announcement");
}
?>

 

this is what i use on my website with WHMCS 3.6.2 I also made it w3c valid.

 

checkout my site to see it working. http://www.scribblehost.com

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