Latest news area

Permalink 2 users found helpful
Hi would anyone be able to suggest the best way to display latest news simple links on the home page that would update auotomaticaly when new content is added to the blog or from another area in the site 1 line would be fine as per attached screen shot

1 Attachment

clairec
View Replies:
chunksmurray replied on at Permalink Reply
chunksmurray
Check out the page list block, it should be able to do what you are looking for.

I needed to do something similar, pulling 'latest news' items from a news section using the page list block. The only custom work needed was a template to format the styling of the block to suit.
Mnkras replied on at Permalink Reply
Mnkras
all you need to do is add a page attribute or just us the existing is_featured attribute then make a custom template for the page list block
clairec replied on at Permalink Reply
clairec
Cheerso!
Do you know if there is any documentation on this in the forums?
andrew replied on at Permalink Reply
andrew
This kind of goes over it:

http://www.concrete5.org/help/building_with_concrete5/developers/un...

However, you probably don't need to read that whole thing. I'd do this.

1. Add a page list block to that area. Set it up to show most recent (or use the "show featured only" option in the page list block, if you have a really recent version of concrete5. ). Set this block to only show 1 item, and set it to show most recent first.

2. Make a new directory in your local blocks directory:

blocks/page_list/templates/one_line_summary.php

3. Copy concrete/blocks/page_list/view.php into that file.

4. Go into the one_line_summary.php file and remove the DIV with the class "ccm-page-list-description" (since you don't want the description here.)

5. Make sure your stylesheet styles the h3 inside this area appropriately.

I believe that would do it.
melat0nin replied on at Permalink Reply
melat0nin
I've adapted your advice to my own needs and it works great, but I was wondering if it's possible to add the date of the item to the template.

Any thoughts?
Mnkras replied on at Permalink Reply
Mnkras
on the day created or edited or what?
melat0nin replied on at Permalink Reply
melat0nin
I guess the date created, as most news items won't be edited once they're 'live'. Something like this:

NEWS ITEM HEADING
News item content. Lorem ipsum dolor sit amet.
15 Jan 2010

My template is fine, I just need a function to display the date below each item.
Mnkras replied on at Permalink Reply
Mnkras
here try this:

<?php     
Loader::model('page_statistics');  
echo strftime('%x ' . t('at') . ' %l:%M %p', strtotime(PageStatistics::getVersionDateCreated())); ?>
melat0nin replied on at Permalink Reply
melat0nin
No dice I'm afraid:

Fatal error: Call to undefined method PageStatistics::getversiondatecreated()
Mnkras replied on at Permalink Reply
Mnkras
i know this works for last edit:

<?php   
Loader::model('page_statistics'); 
echo strftime('%x ' . t('at') . ' %l:%M %p', strtotime(PageStatistics::getSiteLastEdit())); 
 ?>


ill see if i can figure out whats wrong
melat0nin replied on at Permalink Reply
melat0nin
Yeah that works to show the last edit date of the entire site (I'm using that successfully on my homepage), but not the individual edit dates of the news item pages.

I'm actually looking to have the last edit date on every page of the site, as well as the news column, so this could be a useful one two counts!
melat0nin replied on at Permalink Reply
melat0nin
Any thoughts? This is the last feature I need for my homepage news area :)
jordanlev replied on at Permalink Reply
jordanlev
Try this:
<?php echo $cObj->getCollectionDateAdded('F j, Y'); ?>

Note that the 'F j, Y' thing is to format the date as "January 19, 2010" -- if you want a different format, seehttp://us.php.net/manual/en/function.date.php... for all the options.

BTW, if you also want to output the author name, you can use this:
<?php echo $cObj->getVersionObject()->getVersionAuthorUserName(); ?>
melat0nin replied on at Permalink Reply
melat0nin
Thanks for the reply!

Unfortunately that doesn't work. I see this:

Call to a member function getCollectionDateAdded() on a non-object in /public_html/concrete5/blocks/page_list/templates/newsitem.php on line 26


:(

Thanks for the heads-up about the date() function - I am used to using that, but alas it's just the concrete5 API that is a bit of a mystery!
jordanlev replied on at Permalink Reply
jordanlev
Hmm... can you paste the entire code of that page? Perhaps it's not being put in the right spot? (It needs to be inside the "for ($i = 0; $i < count($cArray); $i++ ) {" loop and after the "$cobj = $cArray[$i];" line).

Also, I just realized that my $cObj is capitalized, but in the original template it's not, so perhaps that is the problem -- so try this instead:
//For the date:
<?php echo $cobj->getCollectionDateAdded('F j, Y'); ?>
//For the author:
<?php echo $cobj->getVersionObject()->getVersionAuthorUserName(); ?>
melat0nin replied on at Permalink Reply
melat0nin
Thanks, that worked! The problem was 'cObj' instead of 'cobj'.

Works great now :)
donclark replied on at Permalink Reply
donclark
so where can we view an example of this in action???
thx!
clairec replied on at Permalink Reply
clairec
I have it running on my sitehttp://www.gothinkdesign.com
anttivaatainen replied on at Permalink Reply
anttivaatainen
Thanks for this info, prints dates as it should be but.

Is there way to change day names to another language? Im developing Finnish site, so Enlish dates are not ok.

Thanks in forehand!

---- Update ----

Thanks for Fernandos, right way would be to set up php locale (http://php.net/manual/en/function.setlocale.php... ).

I anyway did it like this:
<?php switch ($cobj->getCollectionDateAdded('n')) {
  case '1':   $month = 'Tammikuu';   break;
  case '2':  $month = 'Helmikuu';   break;
  case '3':     $month = 'Maaliskuu';  break;
  case '4':      $month = 'Huhtikuu';   break;
  case '5':      $month = 'Toukokuu';   break;
  case '6';      $month = 'Kesäkuu';      break;
  case '7';      $month = 'Heinäkuu';   break;
  case '8';   $month = 'Elokuu';      break;
  case '9';   $month = 'Syyskuu';      break;
  case '10';   $month = 'Lokakuu';      break;
  case '11';      $month = 'Marraskuu';   break;  
  case '12';      $month = 'Joulukuu';   break;
}
echo $month . $cobj->getCollectionDateAdded(' j, Y'); ?></div>

..so i took month by number (1,2,3...) and translated them directly to Finnish (Tammikuu, Helmikuu, Maaliskuu...),saved it to variable $month and then printed $month.
cannonf700 replied on at Permalink Reply
cannonf700
Hey,
That's a great looking website! You implemented this block really well!
senshidigital replied on at Permalink Reply
senshidigital
What about the simple news add-on?

Great site by the way!