Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2012, 11:35:42 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155406 Posts in 21698 Topics by 7732 Members
Latest Member: hd6ffycn267kn
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Any News with Published Date  (Read 923 times)
allhaas

Offline Offline

Posts: 24


« on: July 17, 2008, 02:40:25 PM »

Hi there

I'd like to show the published date of my news-items within the "anynews" module. But the $publ_date returns just the 1.1.1970. Is there a known workaround?

Thanks
Logged
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #1 on: July 17, 2008, 03:21:18 PM »

The anynews snippet does not fill a $publ_date variable. So that one is empty.

Add the line below somewhere in the "while($data = $result->fetchRow()) {" loop.

Code:
$publ_date = date(DATE_FORMAT,$data['published_when']);

Ruud
Logged

Professional WebsiteBaker Solutions
allhaas

Offline Offline

Posts: 24


« Reply #2 on: July 17, 2008, 03:28:20 PM »

Thanks a lot it works great!

allhaas

Logged
allhaas

Offline Offline

Posts: 24


« Reply #3 on: July 18, 2008, 07:41:33 AM »

Hi Ruud

I just have another anynews question to the publ_date problem.
I am designer - understand some code, but i am not the man who can make the code go round.

So i'd like just to show the day & the month of the publ_date.
You can see the shot in the attachement.
Is there a solution for this problem?

Thank you a lot.

allhaas
Logged
BerndJM

Offline Offline

Posts: 1764



« Reply #4 on: July 18, 2008, 09:10:47 AM »

Hi,

try this (not tested):
Code:
$publ_date = date("d.m.", $data['published_when']);

short explanation:
the date function formats the date given in the 2nd parameter ($data['published_when']) with the format given in the 1st parameter ("d.m.").
For more information about the date function -> http://www.php.net/manual/de/function.date.php

Regards Bernd
Logged

In theory, there is no difference between theory and practice. But, in practice, there is.
allhaas

Offline Offline

Posts: 24


« Reply #5 on: July 19, 2008, 09:33:28 AM »

Hi BerndJM

So it's fine! Thanks a lot!!

This is the code for anynews to show the day and the month: (change Line 98-136)
Code:
// output all new itmes found
$output = "";
if($number_news) {
while($data = $result->fetchRow()) {
        // fill the variable $publ_date_d and $publ_date_m
        $publ_date_d = date("d", $data['published_when']);
        $publ_date_m = date("F", $data['published_when']);
        // strip tags if specified
        if($strip_tags) {
            $data['title'] = strip_tags($data['title']);
            $data['content_short'] = strip_tags($data['content_short']);
        }

        // shorten news text to defined news length (-1 for full text length)
        if($max_news_length != -1 && strlen($data['content_short']) > $max_news_length) {
            $data['content_short'] = substr($data['content_short'], 0, $max_news_length) ."...";
        }
   
        // output news items depending on choosen display mode
        if($display_mode == 2) {
            // OUTPUT NEWS ITEMS AS UNSORTED LIST
            if ($data['title'] != "") {
                $output .= "<li><a href=\"" .WB_URL.PAGES_DIRECTORY .$data['link'] .PAGE_EXTENSION ."\">" .$data['title'] ."</a></li>\n";
            }
        } else {
            // OUTPUT NEWS ITEMS WITH NEWS TITLE, SHORT NEWS TEXT AND READ MORE LINK
            if ($data['title'] != "") {
                $output .= "<p><strong>" .$data['title'] ."</strong></p>\n";
            }
            if($max_news_length !== 0 ) {
                $output .= "<p>" .$data['content_short'] ."</p>\n";
            }
            //$output = "<p>" .$publ_date ."<a href=\"" .WB_URL.PAGES_DIRECTORY .$data['link'] .PAGE_EXTENSION ."\">" .$readmore_text  ."</a></p>\n";
            $output .= "<p class=\"month\">" .$publ_date_m ."</p>";
            $output .= "<p class=\"day\">" .$publ_date_d ."<a href=\"" . WB_URL.PAGES_DIRECTORY .$data['link'] .PAGE_EXTENSION ."\">" .$readmore_text ."</a></p>\n";
            $output .= "<hr />\n";
        }
    }



Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!