Code Snippet: Display news items, anywhere

doc

Hello,

just released v0.80 of the Anynews code snippet on the WebsiteBaker Add-ons repository.

The Readme file was updated accordingly and explains the parameters to use.

Modifications with respect to previous version (v0.70 / v0.71):
+ $group_id supports multiple groups (default:= 0 all groups, X:= group X, for multiple groups: array(2,4,5) )
+ $lang_id = 'AUTO' first checks language in URL (e.g /EN/ --> domain.com/pages/en/page.php) than in LANGUAGE constant

Installation / Update:
Delete a previous version via the WB backend. Then install the latest version from the backend.

Note:
If you have want to upgrade from a version older than v0.70, you need to update your functions calls and templates as explained in this post.

Regards Christian

doc

#276
Hello,

just released v0.71 of the Anynews code snippet on the WebsiteBaker Add-ons repository.

The Readme file was updated accordingly and explains the parameters to use.

Modifications with respect to previous version:
~ moved language specific text outputs (e.g. read more, date/time format settings) to language files
- removed parameters: $header_text, $readmore_text, $no_news_text, $date_time_format
+ removed support for outdated function call display_news_items()
+ use displayNewsItems() instead
+ added option to output news in random order ($sort_by = 4 as requested in the German forum)

Installation / Update:
Delete a previous version via the WB backend. Then install the latest version from the backend.

Remember to adapt your function parameters in code sections and/or the index.php file of your template!!!

Old parameter list:
<?php 
<?php displayNewsItems($group_id$max_news_items$max_news_length$display_mode
  
$header_text$readmore_text$no_news_text
  
$strip_tags$allowed_tags$show_publish_date$date_time_format,
  
$sort_by$sort_order$not_older_than); ?>

?>


New parameter list:
<?php 
displayNewsItems
($group_id$max_news_items$max_news_length$display_mode$lang_id,
  
$strip_tags$allowed_tags$show_publish_date,
  
$sort_by$sort_order$not_older_than); 
?>



If you use custom template files, check and replace the following placeholders:
{ARG_HEADER_TEXT} --> {TXT_HEADER}
{ARG_READMORE_TEXT} --> {TXT_READMORE}
{ARG_NO_NEWS_TEXT} --> {TXT_NO_NEWS}


Requirements:
+ Requires WebsiteBaker 2.7 or higher
+ the old function call display_news_items is no longer supported use displayNewsItems instead
+ check the parameter function

As usual, your feddback, suggestions etc. are welcome.

Regards Christian

doc

Hello,

please post any questions related to anynews in this thread instead of sending a PM at the first place. This may give the hint to other users which may have similar issues. Thanks.

Quote from: question raised via PM... I would realy love to integrate the anynews snippet in a table (for lay-out puposes) in the homepage for website for my school. As you can see on the homepage of http://www.jonatan.be, the cell under "schoolnieuws"  should be filled with the news, but is not. Further on the page I've used the code-module and then put the snippet in it. That does work, but is not quite as pleasent looking. ...

My public answer:
Think this can be achieved by using a custom template file as described in the Anynews README file. Have a look at /modules/anynews/htt/custom_output_display_mode_3.htt.

Try to play around with the template file. Try something like:
<table>
<!-- BEGIN news_block -->
<tr>
<td><strong>{TITLE} {POSTED_WHEN}</strong></td>
<td>{CONTENT_SHORT}<br />
<a href="{LINK}">{ARG_READMORE_TEXT</a>
</td>
</tr>
<!-- END news_block -->
</table>


Remember to set the display mode to 3 as described in the README file. Try the admin tools Addon File editor from the WebsiteBaker repository if you have no glue how to modify the Anynews template files.

Good luck
Christian

doc

#274
Hello,

Quote from: GitrianIf I deactivate "older" news via the WB backend, I can't see them anymore in the news page
Thats true. Released a new version of Anynews at the Addons repository which introduces the variable $not_older_than. This allows you to show only news posted within the last x days. For the last 12 hours simply specify 0.5. Details can be found in the Readme file.

Regards Christian

Gitrian

Hi,

If I deactivate "older" news via the WB backend, I can't see them anymore in the news page (correct me if I'm wrong), so I think I'll have a look at include.php and try to modify the file myself.

Thanks for responding.

Regards Brian

doc

Hi,

this feature would require to modify the code in the file include.php and to add another control parameter to the function. As the function already has 13 parameter, users may get lost with the options.

Another option is to deactivate "older" news via the WB backend manually.

Regards Christian

Gitrian

Hi,

I wondered if it was possible, in addition to the max number of news-items shown, also to specify how old the news-items must be, to be shown on the list ?

For example I want max 5 items and no one older than 1 month.


erpe0812

Yes, that's the template........

Add the link and you are done.

rgds

erpe

babsy

#268
i think i found.... under modules/anynews/htt/detailed_output.htt

looks. like thats its... i just have to customize it now!

anynews is on the right... here:

http://www.is.fo/


i use the latest version.. i think :)

erpe0812


babsy

Do you mean in this code part (i tried, and the pages keep turning blank)? (this is in the module/anynews/index.php ?

// replace the news article dependend template placeholders
               $tpl->set_var(array(
                   'TITLE'                => ($strip_tags) ? strip_tags($row['title']) : $row['title'] ,
                   'CONTENT_SHORT'        => $row['content_short'],
                   'POSTED_WHEN'        => ($display_publish_date) ? date($date_time_format, $row['posted_when']) : '',
                   'PUBLISHED_WHEN'    => isset($row['published_when']) ? date($date_time_format, $row['published_when'])
                                           : date($date_time_format, $row['posted_when']),
                   'LINK'                => WB_URL . PAGES_DIRECTORY . $row['link'] . PAGE_EXTENSION
               ));

erpe0812

Hi

you have to modify the standard template in anynews and add
Quote<a href="{LINK}">{TITLE}</a>
in that row.

rgds

erpe

babsy

to make the "Title" the link also?
anyone who knows?, there was now trouble in the old code, but i just can´t figure it out in this new code?

JonH

Aaahaaaa! That mouse over trick did the job.
Thank's a lot!

doc

#262
Hello,

the group is is numeric. Go the the WB backend and vist the page of type News (not Anynews). Look for the section called: "Modify / Delete Groups" which lists all the groups you have created. Go with the mouse over the group name and look in the browser status bar (in Firefox at the bottom). Here you see a link with the numeric group_id. If you don´t get it, simply click on the link of the group you are interested. The group_id can be found in the URL.

If it still not works, make sure you have assigned the news entries to one of those groups. Per default, news entries are assigned to the group_id 0, you need to add news entries manually to a group to get it working.

The parameter to touch is the first one. If still in doubt, have a look at the README file.

Regards Christian

JonH

#261
Ok, what am I missing?

I have 2 news groups, Group-X and Group-Y and want to display news from Group-X on my front page by using:

<?php displayNewsItems(05502
  
'Latest news''read more''No news available',
  
true'<a><img>'true' (d.m.Y)'11); ?>


What do I put instead of 0 as the first parameter? I tried 1 and I tried Group-X, none worked. It only shows news from all groups...
Is group id same as group title?

Help pls!

(I'm using latest version of wb and anynews)

doc

Hi,

Anynews v0.40 is available on the WebsiteBaker Addons repository.

Main changes:
- anynews function was renamed from display_news_items() into displayNewsItems()
- the old function name still exists, but was marked deprecated, which means it will be removed in future versions
- some code clean up

Regards Christian

daydreamer

Read more links to /index.php on each post not to the actual post?

sparkdigital


doc

Hi Konrad,

this is not possible in any of the Anynews version available. Anynews simply uses the PHP strip_tags function with the option to define tags which should not get removed from the text. However, feel free to change the code to fit your needs.

Regards Christian

sparkdigital

I noticed it is possible to allow certain tags using 'allowed_tags' but is it also possible to only allow these tags (img and a) and exclude any text? This way I could show the image and use that as a link and could make it look a bit more 'designed'.

Thanks,

Konrad

sparkdigital

Thanks Christian,

I was thinking along similar lines but unfortunately I don't think it will work in this scenario - Ill try something else.

Thanks very much for your help though! :wink:

doc

Hi,

anynews only allows to list x news from either all news pages (group id = 0) or from a certain group (group id > 0). However, you can think off calling the function 5 times (one call per group) and limiting anynews to show only one news per group. This in combination with a user defined template (/htt/custom_output_display_mode_X.htt) should do the trick even if it is not that straight forward.

Regards Christian

sparkdigital

Thanks Christian,

I've upgarded to the latest version and followed the instructions in the read me - I understand it orders it based on the date / time, either ascending or descending?

Presuming I have 5 news pages, is there any way to display the top post of each news page rather than just the 5 latest posts?

Thanks!

Konrad