Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2012, 09:40:24 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.
155444 Posts in 21703 Topics by 7731 Members
Latest Member: zvaigzdzius
* Home Help Search Login Register
Pages: [1] 2   Go Down
Print
Author Topic: New module - Latest News (last full news post)  (Read 10943 times)
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« on: October 25, 2008, 10:25:22 PM »

Some time ago I read a request for a module to show the last post from the news module on another page (i.e. homepage). This is common for weblogs.

This module will do just that.
It finds the last post (from a selected group, or from all groups) and displays it.

Other than the news module the post is written within <div>'s, and using a frontend.css (editable in backend > WB2.7) you can style it to your wishes.

version 0.2.2 - 22-12-2010
- fix that enables multiple instances on a single page.

version 0.2.1 - 26-10-2008
- added - the time part of posted_by is not displayed when there is no TIMEFORMAT defined in the language file. (by default)
- added Germand language - thanks to Vyni
- fixed showing posts before their published date/time
- autodetects WB2.6 /2.7 for the functions above (the module will still work on WB2.6)

version 0.2 - 26-10-2008
- added extra pagetitle (allows "Latest post.." message above the news post)
- added choice to display posted_by line
- added choice to display short text
- added choice to display long text
- date and time format strings in language files. (translators, add your locale settings too)

version 0.1 - 25-10-2008
- initial version

Ruud
« Last Edit: December 22, 2010, 11:00:35 PM by Ruud » Logged

Professional WebsiteBaker Solutions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: October 25, 2008, 10:47:46 PM »

Wow, again a really good Idea by yours, Ruud.

I needed exactly that for a Project.

It's so nice, because with this you're able to keept your Site fresh.

 tongue
Best Regards,
Stefek

P.S. I'm really satisfied about this one
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #2 on: October 25, 2008, 11:04:47 PM »

Dear Ruud.

I translated the DE.php

But I don't seem to find the function for "loading images"

Code:
<?php
//Modul Description
$module_description 'Mit diesem Modul ist es m&ouml;glich, die zuletzt ver&ouml;ffentlichte News (des NEWS MODULS) einer ausgew&auml;hlten Kategorie (oder aller Kategorieren) auf einer beliebiegen Seite auszugeben.';

//Variables for the Frontend
$MOD_LATESTNEWS['LOADING_IMAGES'] = 'Loading images';

//Variables for the Backend
$MOD_LATESTNEWS['BACK_TITLE']            = 'Latest News Section';
$MOD_LATESTNEWS['BACK_DESCRIPTION']        = 'Dieses Modul gibt die zuletzt ver&ouml;ffentlichte News des News-Moduls aus.';
$MOD_LATESTNEWS['BACK_GROUP']            = 'Kategorie ausw&auml;hlen';
$MOD_LATESTNEWS['BACK_ANY_GROUP']        = 'aus allen Kategorien';
$MOD_LATESTNEWS['POSTED_BY']            = 'Ver&ouml;ffentlicht von';
$MOD_LATESTNEWS['ON']                    = 'am';
$MOD_LATESTNEWS['AT']                    = 'um';


?>

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
vyni

Offline Offline

Posts: 566


« Reply #3 on: October 26, 2008, 12:28:20 AM »

Hi Ruud,

I´m missing the most important part of the news, when I display it with this module - I miss the short-text.
Is it because You don´t like to read too much?  grin
Or is it because You don´t like to find a complete passage twice in the HP ?  grin

So please have a look, sir!

And than I was fed up of the english date, the month-name was in english. After some searching I discovered every dates, if there are month-names (news) are shown in english. And I found the reason: no locale is set in the language-file. So I searched and found:
Insert setlocale(LC_TIME, "de_DE"); in Your language-file - best file for that is DE.php in folder WB_PATH/languages so You have it WB-wide.
Change it to Your country-code.
Than I inserted "Uhr" in the view.php [ strftime("%H:%M Uhr"... ]
And now I get a line like this:
Veröffentlicht von Webmaster am Sonntag, 26. Oktober 2008 um 02:54 Uhr


@Stefek
loading images =>  lade Bilder
BACK_TITLE = neueste Nachricht

Edit:
This belongs to version v.0.1 only
I found the reason and a solution. Open view.php and change the code a little bit as follows
Go to line (51 and 52)

Code:
       $wb->preprocess($post['content_long']);
        $post_long = $post['content_long'];
and insert this 2 lines
Code:
       $wb->preprocess($post['content_short']);
        $post_short = $post['content_short'];

than keep this unchanged
Code:
       ?>
        <div id="latestnews">
            <div id="title"><h1><?php echo $post['title'];?></h1></div>
            <div id="postedby"><?php echo $MOD_LATESTNEWS['POSTED_BY']; ?> <?php echo getUserFromId($post['posted_by']); ?> <?php echo $MOD_LATESTNEWS['ON']; ?> <?php echo $post_date?> <?php echo $MOD_LATESTNEWS['AT']; ?> <?php echo $post_time?><br/></div>
now change the line
Code:
<div id="news"><?php echo $post_long?></div>
to the following 2 lines
Code:
           <div id="news_s"><?php echo $post_short?></div>
            <div id="news_l"><?php echo $post_long?></div>

save.
Now open frontend.css, rename #nesw to #news_l and insert new ID #news_s with Your preferred definitions.

Ready. Short content shows up.


PS: I enclosed the modified view.php - just rename the txt to php and (remove Uhr if You like) and replace it in the server.
« Last Edit: October 26, 2008, 04:05:49 AM by vyni » Logged

PS: Falls jemand eine Idee hat was zu tun ist und mir das erklären könnt - geh bitte davon aus dass ich ahnungslos bin, was php und so betrifft. Ich kann grad was lesen, kopieren und einfügen,  ungefähr verfolgen und glauben.
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #4 on: October 26, 2008, 01:16:04 AM »

@Stefek
loading images =>  lade Bilder
Yes, I know, but I don't seem to find the function itself.

The another suggestion (short Description), yes your'reright Vyni. I would preffere a possibility to choose if I want to display it or not though.

Best Regards,
Stefek
« Last Edit: October 26, 2008, 01:58:16 AM by Stefek » Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
vyni

Offline Offline

Posts: 566


« Reply #5 on: October 26, 2008, 01:25:26 AM »



Because this is the opening of each article it is a must! No way to let it away.
Logged

PS: Falls jemand eine Idee hat was zu tun ist und mir das erklären könnt - geh bitte davon aus dass ich ahnungslos bin, was php und so betrifft. Ich kann grad was lesen, kopieren und einfügen,  ungefähr verfolgen und glauben.
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #6 on: October 26, 2008, 03:16:18 PM »

Hello Ruud.

Please would you explain where the
$MOD_LATESTNEWS['LOADING_IMAGES'] = 'Loading images';
belongs to.

 smiley

Best Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #7 on: October 26, 2008, 04:33:07 PM »

@stefek
Please would you explain where the
$MOD_LATESTNEWS['LOADING_IMAGES'] = 'Loading images';
belongs to.

Oops, sorry.
That belongs to the Imageflow module. I used that file as a start for the latestnews language file.
I took it out of the NL.php, but forgot the EN version.

No need to translate that one

@vyni
I´m missing the most important part of the news, when I display it with this module - I miss the short-text.
Is it because You don´t like to read too much?  grin
Or is it because You don´t like to find a complete passage twice in the HP ?  grin

So please have a look, sir!
.

I simulated the standard newspage settings (without the links to groups and the "back" to the overview).
The standard news does not display the short text, it is used in the overview page only (where is no long text).
Whenever I use Newspages in a site the short news has a summary of the article and the long news has the full article.

Next version I will add a checkbox where you can select the short and/or the long text (and the posted by line). That way everyone can decide for themselves how your output is built.

Quote
And than I was fed up of the english date, the month-name was in english. After some searching I discovered every dates, if there are month-names (news) are shown in english. And I found the reason: no locale is set in the language-file. So I searched and found:
Insert setlocale(LC_TIME, "de_DE"); in Your language-file - best file for that is DE.php in folder WB_PATH/languages so You have it WB-wide.
Change it to Your country-code.

In the EN.php/NL.php there are examples for the setlocale settings.
Your setting works on *nux OS. For windows you need an extra setting.
Quote
// set the date names to other languages. See:  http://www.php.net/manual/en/function.setlocale.php
//setlocale(LC_ALL, 'nl_NL', 'nld_nld');
//setlocale(LC_ALL, 'de_DE', 'deu_deu');
In this case the 'deu_deu' is valid for Windows (WAMP) platforms.
Note that this only works when the date is built using the strftime() php function.
Typically WB uses the gmdate() function. That one does not respect the setlocale setting.
The strftime function will not respect the dateformat setting you do in WB.

Maybe for WB2.7.1 all gmdate() should be replaced for strftime() with the corresponding formats?


Ruud
Logged

Professional WebsiteBaker Solutions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #8 on: October 26, 2008, 04:41:00 PM »

@stefek
Please would you explain where the
$MOD_LATESTNEWS['LOADING_IMAGES'] = 'Loading images';
belongs to.
...
That belongs to the Imageflow module. I used that file as a start for the latestnews language file.
....
No need to translate that one
Thank Ruud.

Quote
Next version I will add a checkbox where you can select the short and/or the long text (and the posted by line). That way everyone can decide for themselves how your output is built.
Thanks again, Ruud.
This is a great thing.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #9 on: October 26, 2008, 04:46:37 PM »

Wow, again a really good Idea by yours, Ruud.
I needed exactly that for a Project.
It's so nice, because with this you're able to keept your Site fresh.
 tongue
Best Regards,
Stefek
P.S. I'm really satisfied about this one

Thanks again, Ruud.
This is a great thing.

Regards,
Stefek

I assume you like this module?  cool

Ruud
Logged

Professional WebsiteBaker Solutions
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #10 on: October 26, 2008, 06:05:27 PM »

A new version (v0.2) is available.

Added several extra options:

- added extra pagetitle (allows "Latest post.." message above the news post)
- added choice to display posted_by line
- added choice to display short text
- added choice to display long text
- date and time format strings in language files. (translators, add your locale settings too)



Note: The module is upgradeable. No need to uninstall first.

Ruud
« Last Edit: October 26, 2008, 06:09:42 PM by Ruud » Logged

Professional WebsiteBaker Solutions
vyni

Offline Offline

Posts: 566


« Reply #11 on: October 26, 2008, 06:52:40 PM »

Great,

but what do You think of using the posted_when entry instead of published_when - I think this published date will be mostly set to 0:00 because tis is by default 00:00. but posted date is set automatic.

regards

ps: find enclosed the german language file
Logged

PS: Falls jemand eine Idee hat was zu tun ist und mir das erklären könnt - geh bitte davon aus dass ich ahnungslos bin, was php und so betrifft. Ich kann grad was lesen, kopieren und einfügen,  ungefähr verfolgen und glauben.
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #12 on: October 26, 2008, 10:41:50 PM »

but what do You think of using the posted_when entry instead of published_when - I think this published date will be mostly set to 0:00 because tis is by default 00:00. but posted date is set automatic.

The posted_when also changes whenever you change something in an existing message, and is not changeable.
Published_when is at least settable. That way you can decide yourself what is displayed.
Also the anynews snippet and the WB2.7 newspage itself also use published_when by default.

The only "bug" I found myself is that if the post is not yet published, it sill is displayed in this module.
I will change that in the next version.

Ruud

Logged

Professional WebsiteBaker Solutions
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #13 on: October 26, 2008, 11:08:00 PM »

version 0.2.1 is now available. (download from the first post of this thread)

Added: if there is no setting in the language file for the TIMEFORMAT, that part of the "posted_by" line will not be displayed anymore.

Added: German language, thanks to Vyni.

Fixed: Posts that are not yet published are not shown anymore. The newest unpublished is shown.
This will allow you to schedule your homepage content. (i.e. Display a different homepage on Christmas day only)

Ruud
Logged

Professional WebsiteBaker Solutions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #14 on: October 26, 2008, 11:14:11 PM »

I assume you like this module?  cool

Your conclusion is correct, Sir.


Stefek
 smiley


« Last Edit: November 24, 2008, 03:50:40 PM by Stefek » Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
spida

Offline Offline

Posts: 203


« Reply #15 on: November 24, 2008, 03:41:45 PM »

Hi Ruud,

I get the page title displayed additionally with the page's first header (I am using SimplePageHead). How can I get rid of the title?

Cheers,
spida
Logged
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #16 on: November 24, 2008, 03:59:15 PM »

SimplePageHead will set the title (in the browser caption) to whatever is set in the page title field of the page your are watching.
Only for "virtual pages" like a "full news page" or "bakery shop" pages it will try to display something more relevant.

A page created with this module is a normal page, and will have the normal page title, not the title of the news.
I don't think there is much you can do about that.

Ruud

Logged

Professional WebsiteBaker Solutions
spida

Offline Offline

Posts: 203


« Reply #17 on: November 24, 2008, 04:06:39 PM »

Hi Ruud,

maybe I misunderstood which title that is exactly. So, displayed is the news' title as you type it into the field "Title" of a new news. This title, as far as I understand the concept, is otherwise only used to be displayed in the backend list of news, in order to discriminate the news (else, you would just see that you have a number of news, but wouldn't know which one to edit wink )

This title is displayed by your module, then follows the original news' header (<h1> as is in my code), and I would like to not have the title shown, only the header.

I hope you can help me smiley

Cheers,
spida
« Last Edit: November 24, 2008, 04:10:23 PM by spida » Logged
spida

Offline Offline

Posts: 203


« Reply #18 on: November 24, 2008, 04:14:19 PM »

OK, I got it:

This line
Code:
<div id="title"><h1><?php echo $post['title'];?></h1></div>
on apprix. line 74 needs to be commented out.

Cheers,
spida
Logged
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #19 on: November 24, 2008, 04:14:58 PM »

That title is meant to be displayed.
The original settings for the newspage, but also the overview page and the anynews snippet output will by deafult display that.

The simple way to hide it from browsers is to use the css.
There is a "Edit css" button in the backend part.

Change the existing setting for the title to this:
Code:
#latestnews #title {
    display:none;
}
and the title will be hidden.

Ruud

Ruud
Logged

Professional WebsiteBaker Solutions
spida

Offline Offline

Posts: 203


« Reply #20 on: November 24, 2008, 04:19:04 PM »

Yeah, you're right, this is another possible approach. Only that I have to add the styles to my template's stylesheet, since the module's css is ignored when the page is rendered.

Thanks for your help, Ruud!

Good day,
spida
« Last Edit: November 24, 2008, 04:26:23 PM by spida » Logged
spida

Offline Offline

Posts: 203


« Reply #21 on: November 28, 2008, 01:25:20 PM »

Hi Ruud,

if you ever find some time again to work on this really nice mod, I would like to suggest to include the commenting function.

Currently it is possible to display either the news short or long text, in neither cases the commenting function is added though.

Maybe this is different with chios upcoming module "news2" (or whatever the name will be). But with the current core news module the commenting function seems to be ignored by your module.

Best regards,
spida
Logged
tost

Offline Offline

Posts: 7



WWW
« Reply #22 on: February 18, 2009, 06:55:40 PM »

Hello Ruud.

Thanks for a great module. Using it on two sites already.

Here is the Norwegian translation (NO.php) with the date and time setup we use in Norway.


Tost
« Last Edit: February 18, 2009, 06:58:32 PM by tost » Logged
daydreamer

Offline Offline

Posts: 252


« Reply #23 on: March 03, 2009, 11:46:00 AM »

How to link to main news item should there be a link?
Logged
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2294



WWW
« Reply #24 on: March 03, 2009, 11:51:10 AM »

No, this will only display the latest news post (the full post).

If you wat to create a link, the AnyNews snippet will be a better option.
http://addons.websitebaker.org/pages/modules/code-snippets.php

Ruud
Logged

Professional WebsiteBaker Solutions
Pages: [1] 2   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!