Jump to content

Show announcements on your front page with linking.


Recommended Posts

Hey I used the show announcements scripts on my frontpage of my site and wanted to link to my site but didn't work since I used seo friendly url's so here is my solution to it with some php regex.

 

<?php
include("billing/dbconnect.php");
include("billing/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 = $data["announcement"];
$date = fromMySQLDate($date);
/*THIS IS IT ! */
$link = preg_replace("/[^a-zA-z0-9\s\+]/", "", $title);
$link = preg_replace("/[\+]/", "plus", $link);
$link = preg_replace("/[\s]/", "-", $link);
 echo("<p><a style=\"text-decoration: none;\" href=\"billing/announcements/$id/$link.html\"><font color=#cccccc>$date</font> - <font color=#000000><b>$title</b></font></a><br>$announcement</p>");
}
?>

 

(Billing is just where my WHMCS lives on my server correct it to where it is on your server)

Link to comment
Share on other sites

  • 2 weeks later...
Hey I used the show announcements scripts on my frontpage of my site and wanted to link to my site but didn't work since I used seo friendly url's so here is my solution to it with some php regex.

 

<?php
include("billing/dbconnect.php");
include("billing/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 = $data["announcement"];
$date = fromMySQLDate($date);
/*THIS IS IT ! */
$link = preg_replace("/[^a-zA-z0-9\s\+]/", "", $title);
$link = preg_replace("/[\+]/", "plus", $link);
$link = preg_replace("/[\s]/", "-", $link);
 echo("<p><a style=\"text-decoration: none;\" href=\"billing/announcements/$id/$link.html\"><font color=#cccccc>$date</font> - <font color=#000000><b>$title</b></font></a><br>$announcement</p>");
}
?>

 

(Billing is just where my WHMCS lives on my server correct it to where it is on your server)

 

Awesome! I love it, was just actually what i needed for my new site I'm in the works developing!!

Link to comment
Share on other sites

  • 1 year 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