Okay I was told by a friend that this original mod was getting a bit to confusing with all the additions and improvements I made over time. So with this in mind I've replaced my original post with this one.
Hopefully it will be easier to follow (and still work )Mod - Create Latest/Archive News feature for your home page.History: I've been asked quite a few times about the Latest News section I had on my home page and how I did it. Well it was only two HTML pages that I had to manually edit each time to add or move to the archive page. It was also formatted to fit in my site so wasn't easy to install on other 4image sites.
So I've created this quick Mod hoping that it would be helpful to others wanting this function.
What it does: Rather than creating more new tables and pages to create a whole new comment/bulletin board I cheated. This mod actually uses the exiting Comments table and pages (without any changes) to enter in your latest news.
Okay it's not rocket science but it works and gives the results required.
NOTE: Remember each time you add a latest news comment it will add a count to your total comments.
BUT remember as this is a very private category only the administrator will see the full count as other wont have access to it.
So READ THE INSTRUCTIONS BELOW FIRST to see if it's okay for you.
Take a look at my site to see what you think. Then Install this Mod if you want to.
As always before starting any Mod make backup copies of the files you are going to modify(Just in case).Modified files:
./Index.php
./templates/your_template/home.html
./details.php
New Files:
./templates/your_template/news_comment_bit.html
./templates/your_template/archive.html
Step 1. Create simple image to be used to as your Latest_news image as you would any other image.
You can use this one if you want
http://www.newman.d2g.com/Code_help_files/Latest_News.jpg Step 2 Log into your sites Admin Control Panel
Step 3 Create a New Category called something like "News Updates"and set all Permissions to "Private"
Step 4 If you want others to add news then you can update their user settings to give them permissions to this new category.
Step 5 Add the image you created (in step 1) to this category as you would any other image.
VERY IMPORTANT: WRITE DOWN the "image_id" value given when imported (eg 3456). I can't stress how important this is. You will need this number several times during installation of this mod.
YOU HAVE BEEN WARNEDOk! Here's were the code changes start.
Step 6 In your templates directory CREATE NEW TEMPLATE FILE called news_comment_bit.html.
INSERT this code
<tr>
<td class="row2" ><div align="right"><small>(Date Posted: {news_comment_date})</small></div><b>Headline: {news_comment_headline}</b></td>
</tr>
<tr>
<td class="row1" align="left">{news_comment_text}</td>
</tr>
Step 7 Edit index.php
Find :
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
Just BEFORE this, INSERT:
//--------------------------------------------------------
// Latest and Archive News Mod --
// --
// User configurable variables --
// You must change the first 4 variables to meet --
// your requirements: (see notes below) --
// $display_by_count --
// $latest_news_day --
// $show_news_articles --
// $news_image --
//--------------------------------------------------------
$display_by_count = "0"; // values 0 or 1 ....
// .... change this to 0 if display by days posted
// .... or 1 to display fixed number of news articles as Latest
$latest_news_days = "31"; // Number of days news displays at Latest ....
// .... change This to the number of days news shows as Latest
$show_news_articles = "5"; // Number of news articles to show ....
// .... change This to fixed number of articles to display for latest news
$news_image = "*****"; // Change This to your Latest news image id
//----------------------------------------------------
$new_news = (time() - 60 * 60 * 24 * $latest_news_days);
if ($newstype == "latestnewsall"){
$news_type = "latestnewsall";
}
else {
$news_type = "latestnews";
}
$additional_sql = "";
if ($news_type == "latestnews") {
if ($display_by_count) {
$additional_sql .= " c.image_id = '".$news_image."'";
$additional_sql_2 .= " LIMIT ".$show_news_articles;
}
else {
$additional_sql .= " c.comment_date > '".$new_news."' AND c.image_id = '".$news_image."'";
$additional_sql_2 .= "";
}
}
else {
$additional_sql .= " c.image_id = '".$news_image."'";
$clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a> / Archived News";
}
$sql = "SELECT c.comment_headline, c.comment_text, c.comment_date, c.image_id
FROM ".COMMENTS_TABLE." c
WHERE ".$additional_sql."
ORDER BY c.comment_date DESC" .$additional_sql_2 ;
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
$news_comment_row = array();
while ($row = $site_db->fetch_array($result)) {
$news_comment_row[] = $row;
}
$site_db->free_result($result);
// This is the Paging stuff
if ($newstype == "latestnewsall") {
include(ROOT_PATH.'includes/paging.php');
$perpage = $show_news_articles;
$link_arg = $site_sess->url(ROOT_PATH."index.php?newstype=latestnewsall");
$getpaging = new Paging($page, $perpage, $num_rows, $link_arg);
$offset = $getpaging->get_offset();
$site_template->register_vars(array(
"paging" => $getpaging->get_paging(),
"paging_stats" => $getpaging->get_paging_stats()
));
$sql = "SELECT c.comment_headline, c.comment_text, c.comment_date, c.image_id
FROM ".COMMENTS_TABLE." c
WHERE ".$additional_sql."
ORDER BY c.comment_date DESC" .$additional_sql_2."
LIMIT $offset, $perpage";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
$news_comment_row = array();
while ($row = $site_db->fetch_array($result)) {
$news_comment_row[] = $row;
}
}
if (!$num_rows) {
$news_comments = " <b>No New News to report within the last ".$latest_news_days." days.</b>";
}
else {
$news_comments = "";
$bgcounter = 0;
for ($i = 0; $i < $num_rows; $i++) {
$row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
$site_template->register_vars(array(
"news_comment_headline" => format_text($news_comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
"news_comment_text" => format_text($news_comment_row[$i]['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),
"news_comment_date" => format_date($config['date_format']." ".$config['time_format'], $news_comment_row[$i]['comment_date']),
"row_bg_number" => $row_bg_number));
$news_comments .= $site_template->parse_template("news_comment_bit");
}
}
$site_template->register_vars("news_comments", $news_comments);
unset($news_comments);
//-----------------------------------------------------
//---End of Show Latest News -------------------------------
//-----------------------------------------------------
Step 8 at bottom of page Search for
$site_template->print_template($site_template->parse_template($main_template));
Replace with
if ($news_type == "latestnewsall") {
$site_template->print_template($site_template->parse_template(archive));
}
else {
$site_template->print_template($site_template->parse_template($main_template));
}
Step 9 In the code you just added to your Index.php you need to change the 4 variables to meet your sites requirements.
$display_by_count = "0"; Set to values 0 or 1 ....
Set to 0 (Zero) If you want to display by number of days posted
Set to 1 (One) to display a fixed number of Latest News comments.
$latest_news_days = "31"; Set to the Number of days New News comments are displayed before
moving to archive page/link
$show_news_articles = "5";
Set to a fixed number of news comments you want to display at Latest
$news_image = "
*****"; Change this to your Latest news image id (eg 3421) that you got in step 5
Step 10 Edit ./templates/your_template/home.html
Insert this code where you want the
Latest News comments to display
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td align="left" class="head1" height="20" width="100%"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" /><a href="./index.php">Latest News</a></td>
</tr>
<tr>
<td>
<table width="100%" border="1" cellspacing="1" cellpadding="4">
{news_comments}
</table>
</td>
<tr>
<tr>
<td align="right" class="head1" height="20" width="100%"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" /><a href="./index.php?newstype=latestnewsall">News Archive</a> </td>
</tr>
</table>
Step 11 By default 4images only allows 1 comment per image per ip address per given time period. This is to stop your site being spammed with loads and loads of comments. For the Private Latest News image though you may want to enter 2 or 3 news comments at once so to bypass this for just your Latest News Image do this...
Edit ./details.php file
Find:
$sql = "SELECT comment_ip, comment_date
FROM ".COMMENTS_TABLE."
WHERE image_id = $id
ORDER BY comment_date DESC
LIMIT 1";
$spam_row = $site_db->query_firstrow($sql);
$spamtime = $spam_row['comment_date'] + 180;
if ($session_info['session_ip'] == $spam_row['comment_ip'] && time() <= $spamtime && $user_info['user_level'] != ADMIN) {
$msg .= (($msg != "") ? "" : "").$lang['spamming'];
$error = 1;
}
Replace with
if ($id != "****"){ //added for latest news mod
$sql = "SELECT comment_ip, comment_date
FROM ".COMMENTS_TABLE."
WHERE image_id = $id
ORDER BY comment_date DESC
LIMIT 1";
$spam_row = $site_db->query_firstrow($sql);
$spamtime = $spam_row['comment_date'] + 180;
if ($session_info['session_ip'] == $spam_row['comment_ip'] && time() <= $spamtime && $user_info['user_level'] != ADMIN) {
$msg .= (($msg != "") ? "" : "").$lang['spamming'];
$error = 1;
}
}
In the code you just replaced change "
****" to be your Latest_News image id that you wrote down in step 5
Step 12 Create a new template page in your templates directory to show your news archive page and allow paging of old news. I suggest making a copy of your home.html file, renaming it archive.html, edit it and removing all the stuff you don't want to display on your news archive page.
Edit archive.html and insert this code where you want the Archived News Comments Archive to appear
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td align="left" class="head1" height="20">Archived News</td>
<td align="right" class="head1" height="20">{paging}></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="1" cellspacing="1" cellpadding="4">
{news_comments}
</table>
</td>
</tr>
<tr>
<td align="left" class="head1" height="20"> <a href="./index.php">Latest News</a></td>
<td align="right" class="head1" height="20">{paging} </td>
</tr>
</table>
That's it.
Now you can test it to see if it works.
1)Log into your site as your admin account.
2)Find your new Category, remember it's something like News Updates
3)Add a comment or 3 to the Latest News image you created
3)Go back to home page and see the results.
I think thats it.
I tested this documents steps fully on a fresh install of the 4images PHP pages and Default template pages. It worked fine. So if you follow the steps carefully it should work for you first time.
Thanks to Chris for getting on my back and making me do this re-write
Good luck with your sites Everyone.
Fugaziman