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

0 Members and 1 Guest are viewing this topic.

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
[Mod] Latest News and Archive
« on: March 14, 2005, 12:55:57 PM »
copy back from the google cache
-----------------
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

: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 Vividviews 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.

Last edited by Fugaziman on 17.05.2003, 21:03; edited 6 times in total
« Last Edit: April 20, 2005, 06:42:29 AM by V@no »
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Latest News and Archive
« Reply #1 on: March 14, 2005, 02:44:51 PM »
is there any chances u could save the cached pages as .html and send them to an admin here?
this way formating could be restored too ;)

Thanks.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline AntiNSA2

  • Hero Member
  • *****
  • Posts: 774
  • As long as I can finish my site before I die.
    • View Profile
    • http://www.thelifephotography.com
Re: [Mod] Latest News and Archive
« Reply #2 on: March 16, 2005, 06:51:02 AM »
Is it possible with your news and archive board to have different sections of news?

I mean, relative to the category of the template the page the news is found on?

Like, for my category 22 template (CHina)
I want to have a news and archive, for only China....

So that would be like China news and updates,

And then have different news for different categories......

Now, I use different templates for different categories mod, so can I be sure that if there is now specific news for a subcategory, it will use its parents categories news?

 
As long as I can finish my site before I die.

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: [Mod] Latest News and Archive
« Reply #3 on: March 16, 2005, 09:47:09 AM »
this is not my mod - just copied back from google
maybe you should send a message to Fugaziman

sincerly
vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Re: [Mod] Latest News and Archive
« Reply #4 on: April 20, 2005, 06:32:48 AM »
or icon for a new????
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Latest News and Archive
« Reply #5 on: April 20, 2005, 06:42:01 AM »
is there any chances u could save the cached pages as .html and send them to an admin here?
this way formating could be restored too ;)

Thanks.
Ok, I restored the formating from the original post ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline RoadDogg

  • Sr. Member
  • ****
  • Posts: 488
    • View Profile
    • Düsipixel
Re: [Mod] Latest News and Archive
« Reply #6 on: April 20, 2005, 10:20:53 AM »
where to get this sitemap Mod on http://www.1024x768wallpapers.com/ main page (below news Mod) ?
I did not find it via search ?
For support requests please don´t forget link to your Gallery/to phpinfo.php
Code: [Select]
<?
phpinfo()
?>
safe_mode must turned OFF
Please check Error Messages

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Latest News and Archive
« Reply #7 on: April 20, 2005, 02:37:28 PM »
where to get this sitemap Mod on http://www.1024x768wallpapers.com/ main page (below news Mod) ?
I did not find it via search ?
and what kind of relation this question has with news mod???
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Re: [Mod] Latest News and Archive
« Reply #8 on: April 20, 2005, 08:20:17 PM »
I like the ability to chose a diferent icon for a new, like Important Icon, Question etc etc
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Latest News and Archive
« Reply #9 on: April 21, 2005, 12:50:11 AM »
I guess, u could always add some html or bbcode in your news? (perhaps into headline would work too?)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Re: [Mod] Latest News and Archive
« Reply #10 on: April 21, 2005, 08:57:39 AM »
yes i try thar but i have a problem with that

when I insert a table it show like 3, 4 empty lines to before the table

and when i insert the image next the text its look bad

maybe with a bbcode table but i dont know how to use it
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [Mod] Latest News and Archive
« Reply #11 on: May 20, 2005, 12:26:24 AM »
hi!

i installed the news and archive mod. 
posting news works without problems.
but the link button to the news archive does not work. Why? i always see the same latest news on home.htm

i followed the instructions to copy the home.htm and rename it into archive.htm and filling in the posted code.
but i cannot sse the archive.

any solutions to solve my prob.

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [Mod] Latest News and Archive
« Reply #12 on: May 22, 2005, 01:11:58 AM »
ok no i have a link working from the latest news to the archived news.

the mod shows the latest news correct :)

but in my newsarchive.html with the filled in code like to see in the instructions are NO archived news shown :(
and paging through them also does not work :(

please help me!

you could have a look at www.industrie-gravuren.de/galerie


Offline kindian

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: [Mod] Latest News and Archive
« Reply #13 on: July 11, 2005, 02:40:07 PM »
same problem here  :(