Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Help & Support Display News Based on Date Created
1 2
Gallion311
Posted on 06 Apr 2010, 14:38:20

Access: Member
Total Posts: 8
Joined: 2010-04-06

Hey Chris, had a quick one for you.

First off, I love the script; I tried 3 or 4 of these before I settled on N13 and it's much easier in several ways.

Anyway I'm using the method described here to display my headlines on page A; that open the full story on page B.

We post 3 news stories every 2 months, and I'd like to find a method to separate the stories as such.

So the headlines page would show something like:

Oct - Nov 2009

Story1
Story2
Story3

Dec - Jan 2010

Story1
Story2
Story3

Etc...

I have 2 possible solutions but neither of them are perfect.

1. I could create categories based on the 2 months cycle (OctNov09, DecJan10), and then use the $cat[] variable to seperate them; but I'd like to include actual categories, so I'd like to avoid that if possible.

2. I could modify the author (which will always be me) in phpmyAdmin to months and display them based on the $author[] variable, but naturally that feels like a bit of a hack.

So is there a more official method I'm just not thinking of? Can you think of a better solution?

Thanks Man,
Ryan

*Also, I really do appreciate the script, and would be interested in making a donation if this required some custom tweaking on your part...perhaps a new $dateposted[] variable as a means to filter the stories.

#2223
Last edited by Gallion311 at 2010-04-06 14:39:49 Reason:
Chris
Posted on 06 Apr 2010, 16:49:06

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

While this isn't exactly what you want it does organize the news articles by month. It outputs them like so

Code:
July 2010
A post made in july

April 2010
Anothera article
Welcome to N-13 News 3.5

March 2010
asd asds 

January 2010
xa das as


And here's the code to do that

Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';

// Grab all news articles
$allnews = DataAccess::fetch("SELECT title,timestamp,$newstable.id,author FROM $newstable 
LEFT JOIN 
$newsgroupcats ON $newstable.id = $newsgroupcats.storyid
LEFT JOIN 
$newscats ON $newsgroupcats.catid = $newscats.id
WHERE approved = '1'
ORDER BY timestamp DESC"
);

$dates = array();
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// loop through articles and grab the year, month and day then store them in the $dates array
$x = 0;
foreach(
$allnews AS $news){
    
$y = date("Y", $news['timestamp']);
    
$m = date("n", $news['timestamp']);
    
$d = date("d", $news['timestamp']);    
    
    
// sort the articles into groups by month
    
$dates[$y][$m][$d]['id']        = $news['id'];
    
$dates[$y][$m][$d]['title']        = $news['title'];
    
$dates[$y][$m][$d]['timestamp']    = $news['timestamp'];
    
$dates[$y][$m][$d]['author']    = $news['author'];

    
$x++;
}

$i = 0;
/// loop trough the new dates array starting with the year
foreach($dates AS $year=>$val){
    
// loop through each month
    
foreach($val AS $key2=>$val2){
        echo 
$months[$key2 - 1] . ' ' . $year . '<br />';
        foreach(
$val2 AS $key3=>$val3){
            
// loop through each news article
            
echo '<a href="news/index.php?id=' . $val3['id'] . '">' .$val3['title'].'</a><br />';
            
        }
        echo 
"<br />";
        
$i++;
    }
}
?>
#2224
Gallion311
Posted on 07 Apr 2010, 18:30:35

Access: Member
Total Posts: 8
Joined: 2010-04-06

Chris,

Thanks for the quick reply; while that code seems to work it's a bit more than I need.

Is it possible to filter the news (just like how it's done with the categories) but using the origauthor column?

This is the duct tape solution I was referring too yesterday where I'd go into phpMyAdmin and relabel those cells as months (OctNov08, DecJan09, etc).

Then use a similar function above the include statement like:

Code:
<?php 
$origauthor
[] = 'OctNov08';
$newsorder = 'ASC'; 
include 
'news/index.php';
?>


Naturally I know this would take some tweaking so if needs be I could make a donation. :smile2:

So in a nutshell I'm looking for another way to filter the stories, identical to how the categories work.
#2232
Aeroh5
Posted on 06 Jan 2011, 22:13:20

Access: Member
Total Posts: 5
Joined: 2011-01-06

Hi there!

I know this is an old topic, but it's exactly what I want.
Problem is, I've tried the code (by Chris) above but it just returns this error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'author FROM LEFT JOIN ON .id = .storyid LEFT JOIN ON .catid = .id WHERE appr' at line 1
Statement: SELECT title,timestamp,.id,author FROM LEFT JOIN ON .id = .storyid LEFT JOIN ON .catid = .id WHERE approved = '1' ORDER BY timestamp DESC
Arguments:
Array
(
)

Can you help? I have no idea...

Thanks!
#3101
Last edited by Aeroh5 at 2011-01-06 22:14:08 Reason:
Chris
Posted on 06 Jan 2011, 22:57:38

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Try this

Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';

// Grab all news articles
$allnews = DataAccess::fetch("SELECT title,timestamp," . NEWS_ARTICLES . ".id,author FROM " . NEWS_ARTICLES . " 
LEFT JOIN " 
. NEWS_GROUPCATS . " ON " . NEWS_ARTICLES . ".id = " . NEWS_GROUPCATS . ".storyid
LEFT JOIN " 
. NEWS_CATS . " ON " . NEWS_GROUPCATS . ".catid = " . NEWS_CATS . ".id
WHERE approved = '1'
ORDER BY timestamp DESC"
);

$dates = array();
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// loop through articles and grab the year, month and day then store them in the $dates array
$x = 0;
foreach(
$allnews AS $news){
    
$y = date("Y", $news['timestamp']);
    
$m = date("n", $news['timestamp']);
    
$d = date("d", $news['timestamp']);    
    
    
// sort the articles into groups by month
    
$dates[$y][$m][$d]['id']        = $news['id'];
    
$dates[$y][$m][$d]['title']        = $news['title'];
    
$dates[$y][$m][$d]['timestamp']    = $news['timestamp'];
    
$dates[$y][$m][$d]['author']    = $news['author'];

    
$x++;
}

$i = 0;
/// loop trough the new dates array starting with the year
foreach($dates AS $year=>$val){
    
// loop through each month
    
foreach($val AS $key2=>$val2){
        echo 
$months[$key2 - 1] . ' ' . $year . '<br />';
        foreach(
$val2 AS $key3=>$val3){
            
// loop through each news article
            
echo '<a href="news/index.php?id=' . $val3['id'] . '">' .$val3['title'].'</a><br />';
            
        }
        echo 
"<br />";
        
$i++;
    }
}
?>
#3102
Aeroh5
Posted on 06 Jan 2011, 23:00:56

Access: Member
Total Posts: 5
Joined: 2011-01-06

Thanks Chris, that works well.

Just one last quick request, can I still have dates on the article display itself, so instead of:

December 2010
Article 1
Article 2

It'd look like:

December 2010
13 Dec Article 1
18 Dec Article 2?

Thanks.. I owe you massively..
#3103
Aeroh5
Posted on 06 Jan 2011, 23:03:11

Access: Member
Total Posts: 5
Joined: 2011-01-06

Something else quickly, it seems to be ignoring my

$nppage = '10';
$cat[] = "News";
$template = 'Test';

requests at the beginning. Is there something I should change so it could work?
Thanks so much.
#3104
Chris
Posted on 07 Jan 2011, 13:35:03

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Because this is a custom code sample, it doesn't really use the template system at all, the only html that gets outputted is in this section

Code:
        echo $months[$key2 - 1] . ' ' . $year . '<br />';
        foreach($val2 AS $key3=>$val3){
            // loop through each news article
            echo '<a href="news/index.php?id=' . $val3['id'] . '">' $val3['title'].'</a><br />';
            
        }



I've made some changes to this, at the top of the script you specify which categories you want to use, based on those categories it'll filter the results, it also shows the date next to each news article title.


Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';

$cat = array();

//Specify categories here
$cat[] = "Cat1";
$cat[] = "Cat2";

// Loop through specified categories to grab the IDs
$catids = array();
$group = '';
foreach(
$cat AS $catname){
    
$catid = DataAccess::fetch(sprintf("SELECT id FROM %s WHERE name = ?", NEWS_CATS), $catname);
    if(
count($catid) > 0){
        
$catids[] = $catid['0']['id'];
        
$group .= $catid['0']['id'] . ', ';
    }
}
$group = trim($group, ", ");


// Grab all news articles
$allnews = "SELECT title,timestamp," . NEWS_ARTICLES . ".id,author FROM " . NEWS_ARTICLES . " 
LEFT JOIN " 
. NEWS_GROUPCATS . " ON " . NEWS_ARTICLES . ".id = " . NEWS_GROUPCATS . ".storyid
LEFT JOIN " 
. NEWS_CATS . " ON " . NEWS_GROUPCATS . ".catid = " . NEWS_CATS . ".id
WHERE approved = '1'"
;

if(
count($catids) > 0){
    
$allnews .= " AND " . NEWS_ARTICLES . ".id IN (SELECT " . NEWS_GROUPCATS . ".storyid FROM " . NEWS_GROUPCATS . " WHERE type = 'news' AND catid IN ($group))";
}

$allnews .= "ORDER BY timestamp DESC";
$allnews = DataAccess::fetch($allnews);


$dates = array();
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// loop through articles and grab the year, month and day then store them in the $dates array
$x = 0;
foreach(
$allnews AS $news){
    
$y = date("Y", $news['timestamp']);
    
$m = date("n", $news['timestamp']);
    
$d = date("d", $news['timestamp']);    
    
    
// sort the articles into groups by month
    
$dates[$y][$m][$d]['id']        = $news['id'];
    
$dates[$y][$m][$d]['title']        = $news['title'];
    
$dates[$y][$m][$d]['timestamp']    = $news['timestamp'];
    
$dates[$y][$m][$d]['author']    = $news['author'];

    
$x++;
}

$i = 0;
/// loop trough the new dates array starting with the year
foreach($dates AS $year=>$val){
    
// loop through each month
    
foreach($val AS $key2=>$val2){
        echo 
$months[$key2 - 1] . ' ' . $year . '<br />';
        foreach(
$val2 AS $key3=>$val3){
            
// loop through each news article
            // Show dat next the title of article
            
echo date('d M', $val3['timestamp']) .' <a href="news/index.php?id=' . $val3['id'] . '">' .$val3['title'].'</a><br />';
            
        }
        echo 
"<br />";
        
$i++;
    }
}
?>


Make sure each category has at least one news article assigned to it, that's the only problem I can see this having.
#3111
Aeroh5
Posted on 07 Jan 2011, 13:56:50

Access: Member
Total Posts: 5
Joined: 2011-01-06

Thank you so much for your reply..

My only problem now is that when articles are clicked they go to an unspecified completely new page, and nothing has any kind of style. I see what you said about the template, but how would I be able to style it (or is that just not an option at all?) ?

Thank you!
#3112
Chris
Posted on 07 Jan 2011, 14:05:03

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

This is the section that controls what gets shown on the page

Code:
foreach($dates AS $year=>$val){
    // loop through each month
    foreach($val AS $key2=>$val2){
        echo $months[$key2 - 1] . ' ' . $year . '<br />';
        foreach($val2 AS $key3=>$val3){
            // loop through each news article
            // Show dat next the title of article
            echo date('d M', $val3['timestamp']) .' <a href="news/index.php?id=' . $val3['id'] . '">' .$val3['title'].'</a><br />';
            
        }
        echo "<br />";
        $i++;
    }
}


Notice the line

Code:
        echo $months[$key2 - 1] . ' ' . $year . '<br />';


If you were to change this to something like

Code:
        echo '<span class="header">' . $months[$key2 - 1] . ' ' . $year . '</span><br />';


Then you can style it by adding some css for the "header" class.

When you click on a news article, it is getting redirected to whichever page you specify on this line

Code:
echo date('d M', $val3['timestamp']) .' <a href="news/index.php?id=' . $val3['id'] . '">' .$val3['title'].'</a><br />';


In this case, "news/index.php", change this to go to another page you've created that has the news included into it.

#3113
Last edited by Chris at 2011-01-07 14:05:19 Reason:
1 2
Network-13.com © 2013