drilonb Posted July 12, 2011 Share Posted July 12, 2011 Hello Processwire i have trouble with date in blog post, i like to put date when i post a article i am puting in template like this <?php $languages = $session->language; $children = $pages->get("/news/")->children("sort=-created, limit=5"); foreach($children as $news) { if($session->language) { $titulli = $news->{'headline_'.$session->language}; $shkurtimi = $news->{'body_'.$session->language}; }else{ $shkurtimi = $news->body_en ; $titulli = $news->headline_en ; } $shkurti = substr( $shkurtimi , 0, 250); echo " <h2> >$titulli | {$news->created} </h2> <p><a class='linkulajme' href='{$news->url}'>$shkurti</a></p> "; } echo "<ul class='MarkupPagerNav'>"; echo $children->renderPager(); echo "<ul>"; and in web look only like this: <h2> >$titulli | {$news->created} </h2> (>Viti i ri | [b]1310476537[/b]) PS, also i create a field datat and select date time but show only this date in page >Viti i ri | 12 / 31 / 1969 - 7:00 pm //edits: 14:07 adamkiss: Edited title & syntax formatting. Please use BBCode's [ code ] tag (without spaces) to format PHP (or other) code. Also, use as descriptive title/subject as possible. 15:00 adamkiss: added solved tag Link to comment Share on other sites More sharing options...
Adam Kiss Posted July 12, 2011 Share Posted July 12, 2011 Since $page->created is a system created timestamp, I believe you can't have it returned formatted, as this field simply returns timestamp. Use date() function with your desired format, e.g.: <?php $dateFormatted = date('d.m.Y', $page->created); echo "<h2> $title | $dateFormatted</h2>"; Link to comment Share on other sites More sharing options...
drilonb Posted July 12, 2011 Author Share Posted July 12, 2011 Well perfect now its working nice >New yeah | 12/07/2011 - 12:15 pm $dateFormatted = date('d/m/Y - g:i a', $page->created); Thanks ADAMKISS always helpful Link to comment Share on other sites More sharing options...
ryan Posted July 12, 2011 Share Posted July 12, 2011 I'm thinking maybe we should have built-in date formatting for the 'created' and 'modified' fields. What do you guys think, maybe an alternate syntax for accessing the formatted version? Like $page->dateCreated is the formatted version of $page->created? It would just be formatted by whatever is set to $config->dateFormat. Link to comment Share on other sites More sharing options...
slkwrm Posted July 20, 2011 Share Posted July 20, 2011 I'm thinking maybe we should have built-in date formatting for the 'created' and 'modified' fields. What do you guys think, maybe an alternate syntax for accessing the formatted version? Like $page->dateCreated is the formatted version of $page->created? It would just be formatted by whatever is set to $config->dateFormat. Hi, Ryan I see two sides here The good is that it makes template code cleaner and I don't have to open my php cheatsheet. The bad is that such things make api bloat as time goes and make me lazier And IMHO very often various date formatting is needed depending on the context. Link to comment Share on other sites More sharing options...
Pete Posted July 20, 2011 Share Posted July 20, 2011 It's a good idea ryan, but I agree with slkwrm on this one - on a lot of sites I've worked on I'll format dates differently for different things. News articles on a site's homepage tend to get a long version of the date (Wednesday 20th July 2011) whereas on the same page I might have a little list on a sidebar pulling just page titles for "last 10 files uploaded" or something whereby it would just be the title and a short version of the date, so the date format would be 20th Jul '11 or something like that. I have seen it in forum software where there are config settings for both occasions though, so a config setting for long date format and short date format and to be honest that might not be a bad way to go as the majority of the time I'd only use two different options. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now