• [Mod] Latest News and Archive 5 0 5 1
Currently:  

Author Topic: [Mod] Latest News and Archive  (Read 157095 times)

0 Members and 1 Guest are viewing this topic.

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
[Mod] Latest News and Archive
« on: April 13, 2003, 04:37:23 AM »
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 :wink:  )


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

 :arrow: 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

 :arrow: Step 2  Log into your sites Admin Control Panel

 :arrow: Step 3  Create a New Category called something like "News Updates"and set all Permissions to "Private"

 :arrow: Step 4  If you want others to add news then you can update their user settings to give them permissions to this new category.

 :arrow: 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 WARNED

Ok! Here's were the code changes start.

 :arrow: Step 6  In your templates directory CREATE NEW TEMPLATE FILE called news_comment_bit.html.

INSERT this code
Code: [Select]
<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>

 :arrow: Step 7  Edit index.php

Find :
Code: [Select]
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------

Just BEFORE this, INSERT:
Code: [Select]
//--------------------------------------------------------
// 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>&nbsp;/&nbsp;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 = "&nbsp;&nbsp;&nbsp;<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   -------------------------------
//-----------------------------------------------------

 :arrow: Step 8  at bottom of page Search for
Code: [Select]
$site_template->print_template($site_template->parse_template($main_template));
 


Replace with
Code: [Select]
if ($news_type == "latestnewsall") {  
  $site_template->print_template($site_template->parse_template(archive));      
}  
else {  
  $site_template->print_template($site_template->parse_template($main_template));  
}
 
 :arrow: 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

 :arrow: Step 10  Edit ./templates/your_template/home.html
Insert this code where you want the Latest News comments to display
Code: [Select]
<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>&nbsp;&nbsp;</td>
    </tr>
</table>

 :arrow: 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:
Code: [Select]
$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
Code: [Select]
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

 :arrow: 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
Code: [Select]
<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
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
cna you share
« Reply #1 on: April 14, 2003, 01:29:45 AM »
This mood I always wait ,nice job
Fugaziman


Can you share what code to add to make  paging in your comment :?:  :?: :wink:

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
[Mod] Latest News and Archive
« Reply #2 on: April 14, 2003, 03:49:22 AM »
Mantra.

I've played about with my member.php file so much that I wouldn't know where to start instructiong you how to add the paging bit to yours. :oops:
BUT...
If you want to compare my files to yours and make the changes you can download them here
http://www.newman.d2g.com/code_help_files/member_comment_paging.zip

I've include the template page as well as you need to add the {paging} variable conditionally. You'll know what I mean when you see it.   :?  

Hope that helps just a little
Fugaziman  8)
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline ai-gu

  • Newbie
  • *
  • Posts: 29
    • View Profile
[Mod] Latest News and Archive
« Reply #3 on: April 14, 2003, 04:01:53 AM »
Hi all,

Any one is here have the MOD like "lastest post in the phpBB forum" to show up on 4images??

Thanks for quick helps

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Latest News and Archive
« Reply #4 on: April 14, 2003, 04:29:12 AM »
It would have been better to post your question in the
"Mods & Plugins (Requests & Discussions)" forum.

Having said that, http://www.4homepages.de/forum/viewtopic.php?t=4648

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
[Mod] Latest News and Archive
« Reply #5 on: April 14, 2003, 05:11:55 AM »
thanks Fugaziman, I will try.

 :D

Offline PuCK

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • http://www.acidarts.net
[Mod] Latest News and Archive
« Reply #6 on: April 14, 2003, 11:36:09 AM »
Great MOD. It worked right away but I encountered one little "problem":

Code: [Select]
$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 != "") ? "<br />" : "").$lang['spamming'];
      $error = 1;


must be replaced with:
Code: [Select]
if ($id != "8136"){   //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 != "") ? "<br />" : "").$lang['spamming'];
      $error = 1;
       }


So without the last }

Also it's better to change the lins of the spacer images:

replace
Code: [Select]
"./templates/newman_grey/images/spacer.gif"


with:

Code: [Select]
"{template_url}/images/spacer.gif"

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
Amended script in my Mod
« Reply #7 on: April 14, 2003, 03:49:31 PM »
OOps  :oops:

I forgot about that one. I've amended the code above in my script to add your changes.
Thanks for checking my mod for me.

Fugaziman  8)
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[Mod] Latest News and Archive
« Reply #8 on: April 15, 2003, 02:41:33 PM »
great mod!

i think it would be even better if all registed users could post news or articles on it, and it would be really cool if there was a "leave comment" to every single news/article posted.

i'm now working on something of this kind but my knowledge in coding isn't the best.
u can check what i achive here:
http://www.web-fxdesigns.com/4images/

it's only a test gallery, and it's in portuguese.
thanks[/url]

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Fantastic
« Reply #9 on: April 15, 2003, 07:45:44 PM »
Fantastic Mod

This is a great mod, I was hand editing the template everytime I wanted to add a bit of info to the home page in the form of a news update.  This is great since as admin I can delete the comments when they are out of date or taking up too much space on the home page.

Thank you very very very much for making my life a little easier.

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
[Mod] Latest News and Archive
« Reply #10 on: April 16, 2003, 04:43:25 AM »
How to make paging for this mod???



The last time Fugaziman member.php it's hard to understand.
 :wink:

Offline bag53

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
[Mod] Latest News and Archive
« Reply #11 on: April 17, 2003, 07:49:22 AM »
Instead of time limit on how long they stay up, a post limit would be better. Like set it to only show 10 news posts displacing older ones. Then the older news would move to an archive paging system.

I've been looking for a better way to post news in 4images. Right now I have a hacked up b2 from cafelog running on my site. Don't ask me how I did it. You may not want to do it since it is really chopped up.

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
This should be easy to do...
« Reply #12 on: April 17, 2003, 04:29:40 PM »
Quote
set it to only show 10 news posts displacing older ones


This should be quite easy to do but I wont be able to get round to it until probably later today (some of us have to work as well as have fun  :D ).

I'll post a code change soon.

Fugaziman
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline Fugaziman

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
    • http://www.1024x768wallpapers.com
Done
« Reply #13 on: April 18, 2003, 02:43:22 AM »
Quote
set it to only show 10 news posts displacing older ones


Okay it's done.
I Have changed the code you add to your index.php, (see first post) to allow you the choice of displaying a fixed number of News Comments or News comments posted within a set number of days.

And all you have to do is set a single variable to  0 or 1 depending on your preference   :)

Somebody asked about
Quote
paging
for this Mod !!! I'll look into it over the next couple of days to see if I can get it to work.

Hope that helps
Fugaziman
Please take time to visit us at ...
http://www.1024x768wallpapers.com
And don't forget to leave a comment or message.

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
thanks
« Reply #14 on: April 18, 2003, 05:30:32 PM »
thanks Fugaziman :lol:

 

Post your comments here