[RevCMS]News List - News Archiving (Today, Yesterday, Last Week)

Wickd

The first member of the Knights of the Pink Table
Jan 15, 2013
1,936
612
Hey DevBest, Wickd here.
I'll be releasing a small script that allows News Archiving on RevCMS!I hope you boys will enjoy this!

How to set up this script? (If running on r63b make sure you change from "cms_news" to "site_news")

  • Locate "
    <div id="article-archive">
    <ul>"
  • After that paste this code
    Code:
    <?php
                                                                            {
                                                                                    for ($i = 0; $i < 6; $i++)
                                                                                    {
                                                                                            $sectionName = "";
                                                                                            $sectionCutoffMax = 0;
                                                                                            $sectionCutoffMin = 0;
                                                                                          
                                                                                            switch ($i)
                                                                                            {
                                                                                                    case 0:
                                                                                                  
                                                                                                            $sectionName = 'Today';
                                                                                                            $sectionCutoffMax = time();
                                                                                                            $sectionCutoffMin = time() - 86400;
                                                                                                            break;
                                                                                                          
                                                                                                    case 1:
                                                                                                  
                                                                                                            $sectionName = 'Yesterday';
                                                                                                            $sectionCutoffMax = time() - 86400;
                                                                                                            $sectionCutoffMin = time() - 172800;
                                                                                                            break;
                                                                                                          
                                                                                                    case 2:
                                                                                                  
                                                                                                            $sectionName = 'This week';
                                                                                                            $sectionCutoffMax = time() - 172800;
                                                                                                            $sectionCutoffMin = time() - 604800;
                                                                                                            break;
                                                                                                          
                                                                                                    case 3:
                                                                                                  
                                                                                                            $sectionName = 'Last week';
                                                                                                            $sectionCutoffMax = time() - 604800;
                                                                                                            $sectionCutoffMin = time() - 1209600;
                                                                                                            break;
                                                                                                          
                                                                                                    case 4:
                                                                                                  
                                                                                                            $sectionName = 'This month';
                                                                                                            $sectionCutoffMax = time() - 1209600;
                                                                                                            $sectionCutoffMin = time() - 2592000;
                                                                                                            break;
                                                                                                          
                                                                                                    case 5:
                                                                                                  
                                                                                                            $sectionName = 'Last month';
                                                                                                            $sectionCutoffMax = time() - 2592000;
                                                                                                            $sectionCutoffMin = time() - 5184000;
                                                                                                            break;
                                                                                            }
                                                                                          
                                                                                            $q = "SELECT * FROM cms_news WHERE published >= " . $sectionCutoffMin . " AND published <= " . $sectionCutoffMax .  " ORDER BY published DESC";
                                                                                            $getArticles = mysql_query($q);
                                                                                            if (mysql_num_rows($getArticles) > 0)
                                                                                            {
                                                                                                    echo '<h2>' . $sectionName . '</h2>
                                                                                                    <ul>';
                                                                                                  
                                                                                                    while ($a = mysql_fetch_assoc($getArticles))
                                                                                                    {
                                                                                                            echo '<li>            
                                                                                                                    <a href="http://lwickedev.net/index.php?url=news&id=' . $a['id'] . '">' . $a['title'] . '&nbsp;&raquo;</a>
                                                                                                            </li>';
                                                                                                    }
                                                                                                  
                                                                                                    echo '</ul>';
                                                                                            }
                                                                                    }
                                                                            }
                                                                            ?>
 
Last edited:

twentyfour

New Member
Nov 16, 2014
16
3
works beautifully! just needs some css touchup. another thing for r63b users:
change
PHP:
$q = "SELECT * FROM cms_news WHERE published >= " . $sectionCutoffMin . " AND published <= " . $sectionCutoffMax .  " ORDER BY published DESC";

to
PHP:
$q = "SELECT * FROM site_news WHERE timestamp >= " . $sectionCutoffMin . " AND timestamp <= " . $sectionCutoffMax .  " ORDER BY timestamp DESC";

well, mines is called timestamp, im not sure about everyone else
 

Janzeer

Headmaster Of Hogwart's
Apr 30, 2012
522
47
Where do you locate this? "
<div id="article-archive">
<ul>" " can't seem to find in my news.php. :eek:
 

JackH

Member
Feb 11, 2013
29
1
You didn't even make this, this is directly taken from Uber and you converted it. Takes like 5 minutes
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
It's nice, but the actual full archive would be nicer.

And I also believe JackH is correct.
 

JackH

Member
Feb 11, 2013
29
1
Here, I added this to my hotel and realised it wouldn't show you what article you had picked (Like it does on Uber). So I fixed it up for you :)

Code:
<?php
    {
    for ($i = 0; $i < 6; $i++)
        {
            $sectionName = "";
            $sectionCutoffMax = 0;
            $sectionCutoffMin = 0;
        
            switch ($i)
            {
                    case 0:
                
                            $sectionName = 'Today';
                            $sectionCutoffMax = time();
                            $sectionCutoffMin = time() - 86400;
                            break;
                        
                    case 1:
                
                            $sectionName = 'Yesterday';
                            $sectionCutoffMax = time() - 86400;
                            $sectionCutoffMin = time() - 172800;
                            break;
                        
                    case 2:
                
                            $sectionName = 'This week';
                            $sectionCutoffMax = time() - 172800;
                            $sectionCutoffMin = time() - 604800;
                            break;
                        
                    case 3:
                
                            $sectionName = 'Last week';
                            $sectionCutoffMax = time() - 604800;
                            $sectionCutoffMin = time() - 1209600;
                            break;
                        
                    case 4:
                
                            $sectionName = 'This month';
                            $sectionCutoffMax = time() - 1209600;
                            $sectionCutoffMin = time() - 2592000;
                            break;
                        
                    case 5:
                
                            $sectionName = 'Last month';
                            $sectionCutoffMax = time() - 2592000;
                            $sectionCutoffMin = time() - 5184000;
                            break;
            }
        
            $q = "SELECT * FROM cms_news WHERE published >= " . $sectionCutoffMin . " AND published <= " . $sectionCutoffMax .  " ORDER BY published DESC";
            $getArticles = mysql_query($q);
            if (mysql_num_rows($getArticles) > 0)
            {
                    echo '<h2>' . $sectionName . '</h2>';
                
                    while ($a = mysql_fetch_assoc($getArticles))
                    {
                        if($a['id'] == $_GET['id'])
                        {
                        echo '' . $a['title'] . '&nbsp;&raquo;';
                        }
                        else
                        {
                        echo '<li><a href="/index.php?url=news&id=' . $a['id'] . '">' . $a['title'] . '&nbsp;&raquo;</a></li>';
                        }
                    }
            }
        }
    }
?>
Here's some screenshots:
ZmOiKQA.png

pHCsnzV.png
 

Users who are viewing this thread

Top