WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Snippet: cwsoft-anynews
  • Print
Pages: 1 ... 3 4 [5] 6 7 ... 10   Go Down

Author Topic: Snippet: cwsoft-anynews  (Read 322137 times)

Offline cwsoft

  • Posts: 605
cwsoft-anynews 2.8.0 RELEASED
« Reply #100 on: February 10, 2013, 10:05:49 AM »
Hello,

cwsoft-anynews v2.8.0 stable is available at GitHub and the WebsiteBaker Add-ons repository.

Updates since last release:
- added Czech and Russian language file (thanks to forum members dana and owk444)
- updated truncate function to latest available version (thanks to dana for the hint)
- implemented more flexible parameter handling via new function getNewsItems()
- added option to invoke cwsoft-anynews via a custom Droplet (requested by owk444)

Since Version 2.8.0 the new function getNewsItems() is included, providing a more flexible configuration via a configuration array. This allows you to specifiy ONLY the parameters you want to change, without taking care of position and order of other possible parameters. To ensure backward compatibility, the function displayNewsItems() will work as before, but was marked "deprecated" in favour of the new and more flexible getNewsItems() function. It's recommended to use the latter function for all your new projects. See README for details.

Anynews Droplet:
Since Anynews v2.8.0 droplet code is included, allowing you to create your own Anynews Droplet usable in WYSIWYG editor or your template by pasting the following three code lines into the Droplet code form.
Code: [Select]
if (! file_exists(WB_PATH . '/modules/cwsoft-anynews/droplet/cwsoft-anynews-droplet.php')) return;
include(WB_PATH . '/modules/cwsoft-anynews/droplet/cwsoft-anynews-droplet.php');
return $output;

The Anynews Droplet supports all Anynews parameters (except the rarely used parameter 'custom_placeholder'). For details about the Droplet function see documentation at GitHub.

Cheers cwsoft
« Last Edit: February 12, 2013, 06:43:51 PM by cwsoft »
Logged

Offline dimlaz

  • Posts: 11
Re: Snippet: cwsoft-anynews
« Reply #101 on: February 10, 2013, 12:04:37 PM »
Hello,

Can please someone help since I am a beginner here.

I have two pages that contain news posts, the one of these news posts are the Latest news, which I want to display the titles and a short description on my homepage.

iI use the following code:
<?php
                   $config = array(
                   'section_id' => 8,
                   'sort_order' => 2,
                   'display_mode' => 2,   
                     );
                     echo getNewsItems($config);
                      ?>
The result is that it displayes the news from both news categories, it wont display only the Latest News category, it seems that the section_id, group_id does not work.

Can someone please help.

Thanks
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #102 on: February 10, 2013, 12:24:30 PM »
Hi,

Quote from: dimlaz
it seems that the section_id, group_id does not work.
Your code won't work. The parameter 'section_id' is no valid Anynews parameter. Your code example sets  'group_id' = 0 (DEFAULT), which outputs news from ALL groups available.

If you want to limit Anynews output to a given section, you need adapt yor config array as follows:

Code: [Select]
$config = array(
  'group_id' => 8,
  'group_id_type' => 'section_id',
);

Details about the supported Anynews parameters are given at GitHub.

Cheers

P.S.: Nice to see people already start using the new syntax :wink:
« Last Edit: February 10, 2013, 12:27:51 PM by cwsoft »
Logged

Offline dimlaz

  • Posts: 11
Re: Snippet: cwsoft-anynews
« Reply #103 on: February 10, 2013, 12:34:29 PM »
 :-)
Great,

Thanks for the help, it works now.

Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #104 on: February 10, 2013, 12:58:18 PM »
Hi,

Quote from: dimlaz
Thanks for the help, it works now.
I thank you for your example allowing to show the more flexible configuration in a real world example.

To achieve what you want with the old displayNewsItems function, one would have needed to provide ALL parameters in right order, even though one needs to change only the first ($group_id) and last parameter ($group_id_type). Sometimes I wish PHP would be more similar to Python.

Cheers
« Last Edit: February 10, 2013, 01:05:57 PM by cwsoft »
Logged

Offline StephanLE

  • Posts: 169
Re: Snippet: cwsoft-anynews
« Reply #105 on: February 10, 2013, 05:04:59 PM »
Can one code section also pass parameters?
Code: [Select]
if (function_exists('getNewsItems')) {
    echo getNewsItems();
}
If so how?
I do not get it out the embed.
Code: [Select]
$max_news_length = 30,
$display_mode = 3,
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #106 on: February 10, 2013, 05:25:25 PM »
Hi,

Quote from: StephanLE
Can one code section also pass parameters?
Note quite sure I really understand what you are after, but lets try.

Option 1: requires cwsoft-anynews >= v2.8.0
Code: [Select]
if (function_exists('getNewsItems')) {
    echo getNewsItems(array(
     'max_news_length' => 30,
     'display_mode' => 3,
    ));
}

Option 2: requires cwsoft-anynews >= v2.8.0
Code: [Select]
if (function_exists('getNewsItems')) {
   $options = array(
     'max_news_length' => 30,
     'display_mode' => 3,
   );
  
    echo getNewsItems($options);
}

The old $parameter = VALUE (displayNewsItems) just translates into 'parameter' => VALUE (getNewsItems).

Tip:You could also create a Droplet and use [[getNewsItems?parameter1=VALUE&parameter2=VALUE2]] in a WYSIWYG section or your template, following the steps explained in the README.

Cheers
« Last Edit: February 10, 2013, 05:36:06 PM by cwsoft »
Logged

Offline StephanLE

  • Posts: 169
Re: Snippet: cwsoft-anynews
« Reply #107 on: February 10, 2013, 07:22:23 PM »
Thank you

You heard me all right.
I chose option 2. It now works as it should.
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #108 on: February 10, 2013, 07:27:25 PM »
Hi,

Quote from: StephanLE on February 10, 2013, 07:22:23 PM
I chose option 2. It now works as it should.
Glad it worked. I prefer this option too, as it is more obvious for the reader.

Cheers
Logged

Offline cwsoft

  • Posts: 605
cwsoft-anynews v2.8.2 RELEASED
« Reply #109 on: February 12, 2013, 06:45:31 PM »
Hello,

cwsoft-anynews v2.8.2 stable is available at GitHub and the WebsiteBaker Add-ons repository.

Updates since last release:
- fixed regression with multiple Anynews Droplet calls at one page/section
- fixed two possible PHP notices/warnings

cwsoft
« Last Edit: February 12, 2013, 06:53:59 PM by cwsoft »
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #110 on: May 10, 2013, 03:03:21 PM »
It seems the section_id and page_id parameters don't work. I have this droplet, which should show the news from news section ID 27, but instead it shows the "no news available" line.

Quote
[[getNewsItems?group_id=27&max_news_items=5&max_news_length=80&display_mode=50&not_older_than=360&group_id_type='section_id']]

And this (use page ID 9) doesn't work either:
Quote
[[getNewsItems?group_id=9&max_news_items=5&max_news_length=80&display_mode=50&not_older_than=360&group_id_type='page_id']]

And also the regular code calls don't seem to work with page_id and section_id...
« Last Edit: May 10, 2013, 03:32:15 PM by Argos »
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #111 on: May 10, 2013, 06:56:12 PM »
Hi Argos,

Quote from: Argos on May 10, 2013, 03:03:21 PM
It seems the section_id and page_id parameters don't work. I have this droplet, which should show the news from news section ID 27, but instead it shows the "no news available" line.

Code: [Select]
[[getNewsItems?group_id=27&group_id_type='section_id']]
Anynews droplet parameters needs to be passed over without quotes (see section_id):
Code: [Select]
[[getNewsItems?group_id=27&group_id_type=section_id]]
Quote from: argos
And also the regular code calls don't seem to work with page_id and section_id...
Can't confirm this. Code inside a code section works for me with cwsoft-anynews 2.8.2 and the example code at GitHub.

If you can't get it working, try it first without the other parameters (just group_id and group_id_type) and double check group_id are right. Hope this helps.

Cheers

P.S.: next version will manage unquoted and quoted droplet parameters to remove this possible error source :wink:
« Last Edit: May 12, 2013, 08:25:33 AM by cwsoft »
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #112 on: May 12, 2013, 08:24:18 AM »
@argos: Did removing the quotes around the cwsoft-anynews droplet parameter solve your issues with the droplet call?
If not what cwsoft-anynews version and WB version are you using?
« Last Edit: May 12, 2013, 08:27:13 AM by cwsoft »
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #113 on: May 17, 2013, 05:09:52 AM »
@argos: Guess no news/feedback are good news and your issues are solved with the infos given two posts before. In other words I assume the reported issue is fixed.
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #114 on: May 17, 2013, 12:00:58 PM »
Wrong assumption. I just didn't have the time to test yet. Especially because I uninstalled the latest version and went back to a previous one that I knew worked fine. Had to continue with this client site. But I will try and test the latest version on my test site asap.
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #115 on: June 05, 2013, 12:34:54 PM »
Is it possible to bypass the default date format set in the Admin Settings, just for the AnyNews function?

I'd like to add classes to the date elements and style the date output, so I can create date "icons" like you see for example on http://code.garyjones.co.uk/style-post-info?
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #116 on: June 05, 2013, 12:56:09 PM »
@argos: Date formats can be defined via Twig date function and a modified Anynews template. If default date filters provided by Twig are not sufficient for you, one can code it's own Twig function or extension to transform whatever is needed.

Cheers
« Last Edit: June 05, 2013, 12:57:41 PM by cwsoft »
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #117 on: June 05, 2013, 05:45:13 PM »
Quote from: cwsoft on June 05, 2013, 12:56:09 PM
@argos: Date formats can be defined via Twig date function and a modified Anynews template. If default date filters provided by Twig are not sufficient for you, one can code it's own Twig function or extension to transform whatever is needed.

I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?

This is my code:

Code: [Select]
{% for news in newsItems %}
<div class="twig_block">
    <div class="twig_date">
        <div class="twig_day">{{news.PUBLISHED_WHEN|date("j")}}</div>
        <div class="twig_month">{{news.PUBLISHED_WHEN|date("M")}}</div>
    </div>
    <div class="twig_title"><a href="{{news.LINK}}">{{news.TITLE }}</a></div>
</div>
{% endfor %}

And I added these classes:
Code: [Select]
.twig_block {display:block;clear:both;width:100%;margin-bottom:10px;min-height:50px;overflow:auto;}
.twig_date {width:20%;min-width:35px;float:left;}
.twig_date .twig_day {background:#a8d591;color:#333;font-weight:bold;text-align:center;font-size:110%;border-radius:4px 4px 0 0;}
.twig_date .twig_month {background:#5c9d3b;color:#fff;text-align:center;border-radius:0 0 4px 4px;font-size:70%;text-transform:uppercase;}
.twig_title {float:right;width:75%;margin-top:-2px;}

This looks like the schreenshot. While the abreviation for June is "Jun" in both English and Dutch, I tested it with "F" instead of "M", and it shows the English "June" instead of the Dutch "Juni".
« Last Edit: June 05, 2013, 11:50:58 PM by Argos »
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #118 on: June 05, 2013, 06:55:17 PM »
Quote from: Argos on June 05, 2013, 05:45:13 PM
I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?
For this task, the datetime filter is used. However, it would need to be activated.

Another option is to create an array in the Twig template holding the Dutch month names from Jan to Dec and use date function to return the month as integer value 1-12 as index for the array. For details see the excellent Twig online help.

Cheers
« Last Edit: June 05, 2013, 10:01:35 PM by cwsoft »
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #119 on: June 05, 2013, 11:27:33 PM »
Way over my head...  :cry:

Doesn't this Twig stuff just add a big layer of complexity to this snippet?
Logged

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #120 on: June 06, 2013, 07:08:59 AM »
Quote from: Argos on June 05, 2013, 11:27:33 PM
Doesn't this Twig stuff just add a big layer of complexity to this snippet?
Not really. Date formating is more a shortcoming of PHP, which was improved in PHP 5.x series.

Twig provides a lot of freedom compared to the previously used template. About all requested features since introduction of Twig could be realized by a customized Template, where before people had to hack the Anynews code itself.

Creating an array with month names is a just one code line in Twig shown in the documentation I linked before , so I don't see the big complexity :wink:

Cheers

P.S.: guess you had no time yet to check the modifications I applied based on your request some weeks ago - or :-)
« Last Edit: June 06, 2013, 07:10:57 AM by cwsoft »
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #121 on: June 06, 2013, 11:56:51 AM »
I'm sure Twig is great for coders, but I'm not a coder  :|

With my limited PHP skills I can tweak WB code a bit sometimes, and with lots of trial & error and lots of help from others I sometimes succeed. But in fact I often don't have clue what code does, and I cannot create code myself. So for me Twig just adds another layer of mumbo jumbo LOL. Don't take it personally, your work to modernize and maintain the modules and snippets is much appreciated!

So what a simple line of code is for you, is an impossibility for me :cry:

But if you help me out here, I can finish the client site today or tomorrow, and I promise after that I'll check out the things we discussed before. So this week. Deal?  :roll:
« Last Edit: June 06, 2013, 11:59:19 AM by Argos »
Logged

Offline marmot

  • Posts: 1103
Re: Snippet: cwsoft-anynews
« Reply #122 on: June 07, 2013, 11:38:05 PM »
Hi,

Quote from: Argos on June 05, 2013, 05:45:13 PM
I almost got it, except that the month is in English, and doesn't follow the locale set in the admin. How can I change that?
maybe this way:
Code: [Select]
find fixed code below
regards
« Last Edit: June 08, 2013, 08:53:43 PM by marmot »
Logged

Argos

  • Guest
Re: Snippet: cwsoft-anynews
« Reply #123 on: June 08, 2013, 01:31:10 AM »
Thanks marmot. It doesn't work however.
Logged

Offline marmot

  • Posts: 1103
Re: Snippet: cwsoft-anynews
« Reply #124 on: June 08, 2013, 08:52:45 PM »
Hi,
Quote from: Argos on June 08, 2013, 01:31:10 AM
Thanks marmot. It doesn't work however.
now it does (just a missing "[" in line 1:
Code: [Select]
{% set germanmonth = ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"] %}
{% for news in newsItems %}
<div class="twig_block">
    <div class="twig_date">
        <div class="twig_day">{{news.PUBLISHED_WHEN|date("j")}}</div>
        <div class="twig_month">{{germanmonth[news.PUBLISHED_WHEN|date("m")]}}</div>
   </div>
    <div class="twig_title"><a href="{{news.LINK}}">{{news.TITLE }}</a></div>
</div>
{% endfor %}

regards
Logged

  • Print
Pages: 1 ... 3 4 [5] 6 7 ... 10   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Snippet: cwsoft-anynews
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2