Jump to content

Announcements on index page


SoBeIt

Recommended Posts

  • 4 weeks later...
  • 2 weeks later...
it's possible to visualize the news without php but only with HTML? :?

 

Well, yes, but it takes a little trickery... here's what I did:

 

First, you have to make one php file.

 

in WHMCS/libs/plugins, I made the file: function.fetch_announcements.php

 

which contains:

 

<?php
function smarty_function_fetch_announcements($params, &$smarty)
{
   if (empty($params['var'])) {
       $smarty->_trigger_fatal_error("[plugin] parameter 'var' cannot be empty");
       return;
   }
   $params['count'] = intval($params['count']);

   $query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,".$params['count'];

   $result = mysql_query($query);
   $out = array();
   while ($data = mysql_fetch_array($result)) {
     $data['date'] = fromMySQLDate($data['date']);
     $data['link'] = 'announcements.php?id='.$data['id'];
     $out[] = $data;
   }
   mysql_free_result($result);
   $announcement_count = count($out);
   if ($announcement_count == 1)
     $out = $out[0];
   elseif ($announcement_count == 0)
     $out = null;

   $smarty->assign($params['var'], $out);
   return '';
}
?>

 

Then in any template inside of WHMCS, you can pull announcements very easily:

 

Here's the code to display the latest announcement:

 

{fetch_announcements var=announcement count=1}
{if $announcement != null}
<div class="announcement">
<h2>{$announcement.title}</h2>
<div class="announcement_body">{$announcement.announcement|truncate:100} <a href="{$announcement.link}">Read more</a></div>
</div>
{/if}

 

now say you want to pull up to the last 5? but only show titles?

 

{fetch_announcements var=announcements count=5}
{if $announcements == null}
<p>We're sorry, there are no announcements.</p>
{else}
<h2>Latest Announcements</h2>
<ul>
{foreach item=announcement key=key from=$announcements}
 <li><a href="{$announcement.link}">{$announcement.name}</a></li>
{/foreach}
{/if}

 

Basically, fetch_announcements acts as a 'shortcut' to all the code to get the content of the announcements. Fun stuff. :)

Link to comment
Share on other sites

  • 3 weeks later...
WO-Jacob

 

many tnx

 

 

is possible to give a scroll on this?

 

like sccroll last 5 or 10 anouncements?

 

Tnx

 

{fetch_announcements var=announcements count=5}
{if $announcements == null}
<p>We're sorry, there are no announcements.</p>
{else}
<div style="width: 100%; height=300px; overflow: scroll;">
<h2>Latest Announcements</h2>
<ul>
{foreach item=announcement key=key from=$announcements}
 <li><a href="{$announcement.link}">{$announcement.name}</a></li>
{/foreach}
</ul>
</div>
{/if}

 

Should do at least close to the trick. :)

Link to comment
Share on other sites

Hi many many tnx for reply

 

but not work for me

 

i have 5 anouncement

 

if i put this code

 

{fetch_announcements var=announcement count=1} {if $announcement != null} {$announcement.title}

 

{$announcement.announcement|truncate:100} Ler Mais

 

 

 

{/if}

 

all work good an i see the last anouncement

 

if i put the other code with the scroll or not

 

i not see any anouncement only the box

 

can you test please?

 

many tnx for the help

Link to comment
Share on other sites

I'm not a professional programer but is somethink like this

For show the last 5 anouncement

 

{fetch_announcements var=announcements count=5}
{if $announcements == null}
<p>We're sorry, there are no announcements.</p>
{else}
<h2>Latest Announcements</h2>
<ul>
{foreach item=announcement key=key from=$announcements}
 <li><a href="{$announcement.link}">{$announcement.announcement|truncate:100}</a></li>
 <div class="announcement_body"><a href="{$announcement.link}">Read more</a></div>
{/foreach}{/if}

 

but the code need improvment

 

if you can i apreciate so much

 

many TNX

Link to comment
Share on other sites

  • 3 weeks later...
can you post up a screenshot of your clienthomearea and show it? :)

 

Here is what i'm using currently:

 

{fetch_announcements var=announcement count=1}

{if $announcement != null}

<div class="announcement">

<h2>{$announcement.title}</h2>

<div class="announcement_body">{$announcement.announcement|truncate:100} <a href="{$announcement.link}">Read more</a></div>

</div>

{/if}

 

 

which produces the attached image...

wo-ss-1.jpg

Link to comment
Share on other sites

  • 7 months later...

Here the code I used:

{php}
function truncate($text) {
$text = substr($text,0,390);
$text = substr($text,0,strrpos($text,' '));
return $text;
}
include("support/dbconnect.php");
include("support/includes/functions.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 = truncate($data['announcement']);
$date = fromMySQLDate($date);
echo'<div style="border:solid 1px #e8e8e8; padding:5px;background-color:#f7f7f7;">'.$date.'*-*<strong><a href="announcements.php?id='.$id.'">'.$title.'</a></strong>
<p class="sfont2">'.$announcement.' <a href="announcements.php?id='.$id.'">...more</a></p></div>';
}
{/php}

Now I start using SEO Friendly URLs.

How can I change <a href="announcements.php?id='.$id.'"> to SEO Friendly???

 

Thanks in advance,

Sergey

Link to comment
Share on other sites

Any ideas? Is it possible to make this URL SEO Friendly?

Any help much appreciated.

 

Here the code I used:

{php}
function truncate($text) {
$text = substr($text,0,390);
$text = substr($text,0,strrpos($text,' '));
return $text;
}
include("support/dbconnect.php");
include("support/includes/functions.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 = truncate($data['announcement']);
$date = fromMySQLDate($date);
echo'<div style="border:solid 1px #e8e8e8; padding:5px;background-color:#f7f7f7;">'.$date.'*-*<strong><a href="announcements.php?id='.$id.'">'.$title.'</a></strong>
<p class="sfont2">'.$announcement.' <a href="announcements.php?id='.$id.'">...more</a></p></div>';
}
{/php}

Now I start using SEO Friendly URLs.

How can I change <a href="announcements.php?id='.$id.'"> to SEO Friendly???

 

Thanks in advance,

Sergey

Link to comment
Share on other sites

  • 3 years later...

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