Info cwsoft-anynews

Anynews: Addon for the CMS WBCE

The code snippet cwsoft-anynews (aka Anynews) is designed to fetch news entries from the News module. Invoke Anynews where you want the news output to appear in your frontend. Optional configuration parameters, HTML templates, content placeholders and CSS definitions allows you to style the news output the way you want. Anynews ships with four templates - including two jQuery sliding effects - ready to use out of the box.

Power users define their own placeholders containing information extracted from the short and/or long news module description. Mastering cwsoft-anynews is possible - but requires you to study the information provided in the section Customize.




The cwsoft-anynews code snippet is licensed under the GNU General Public License (GPL) v3.0.


The minimum requirements to get cwsoft-anynews running on your WBCE installation are as follows:

  • News module
  • PHP 5.3.6 or higher (recommended last stable PHP 5.4.x version)
  • Optional: small modification of your template file to enable jQuery support


  1. download latest archive from here
  2. install the downloaded archive via the WBCE installer

Enable jQuery support (optional)

If you want to use JavaScript effects or jQuery plugins with cwsoft-anynews, you need to add one code line to your frontend template. Open your WBCE frontend template file index.php in the cwsoft-addon-file-editor and search for the following lines.

if (function_exists('register_frontend_modfiles')) {

Change the code lines above as follows:

if (function_exists('register_frontend_modfiles')) {

If you can't find the code above in the index.php of your template, simply add the last code block to the end of your <head></head> section.


As cwsoft-anynews is designed to fetch news items from the News module, you need to install the news module and add some news entries before you can use cwsoft-anynews. If no news are available, the message "No news available yet" is shown. Follow the steps below to add some news entries with the news module.

  1. log into your WBCE backend and go to the Pages section
  2. create a new page or section of type News (set visibility to None)
  3. add some news entries (2-3) from the news page in the WBCE backend

Use Anynews from a page or section

Create a new page or section of type Code in the WBCE backend and enter the following code to it. The cwsoft-anynews output is only visible at the pages/sections of your frontend, which contain this code.

if (function_exists('getNewsItems')) {
    echo getNewsItems();

Use Anynews from your template

To display news items at a fixed position on every page of your frontend, open the index.php file of your default frontend template with the cwsoft-addon-file-editor. Then add the code below to the position in your template where you want the news output to appear.

    if (function_exists('getNewsItems')) {
        echo getNewsItems();

Visit the frontend of your website and check the cwsoft-anynews output.

Use Anynews from a Droplet

You can invoke Anynews via a Droplet call from a WYSIWYG editor or your template. The Droplet accepts the Anynews function parameters in any order. To create an Anynews Droplet, follow the steps below.

  1. create a new Droplet called getNewsItems via WBCE Admin-Tools --> Droplets
  2. enter the following code into the Droplet code section

     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;

Now you can use the Droplet from your WYSIWYG editor or template file via:

[ [getNewsItems?group_id=1,2&display_mode=4] ]

Note: The Anynews Droplet supports all Anynews parameters (except the rarely used parameter 'custom_placeholder').


The cwsoft-anynews output can be customized to your needs by three methods:

  1. parameters/configuration array passed to the cwsoft-anynews function
  2. customized cwsoft-anynews template files templates/display_mode_X.htt
  3. customized CSS definitions in file /css/anynews.css

Anynews configuration

An overview of all supported configuration options is given in the section supported configuration options.

Calling getNewsItems without configuration array uses the DEFAULTS below:

$config = array(
    'group_id_type' => 'group_id',
    'group_id' => 0,
    'display_mode' => 1,
    'start_news_item' => 0,
    'max_news_items' => 10,
    'max_news_length' => -1,
    'strip_tags' => true,
    'allowed_tags' => '<p><a><img>',
    'custom_placeholder' => false,
    'sort_by' => 1,
    'sort_order' => 1,
    'not_older_than' => 0,
    'lang_id' => 'AUTO',
    'lang_filter' => false,

// calling getNewsItems() without configuration array uses the defaults above
echo getNewsItems();

Example: To show only news associated to sectionID=8 and to set display_mode=4 the default configuration can be overwritten. Omitted paramters are set to the DEFAULTS shown above.

// customized cwsoft-anynews function call
$config = array(
    'group_id_type' => 'section_id',
    'group_id' => 8,
    'display_mode' => 4,
echo getNewsItems($config);

Supported configuration options

  • group_id_type: defines group type used by group_id to extract news entries from [supported: 'group_id', 'page_id', 'section_id', 'post_id')]

  • group_id: only show news which IDs match given group_id_type (default 'group_id') [0:all news, 1..N, or array(2,4,5,N) to limit news to single Id or multiple Ids, matching group_id_type]

  • display_mode: ID of the Anynews template to use (/templates/display_mode_X.htt) [1:details, 2:list, 3:better-coda-slider, 4:flexslider, 5..98 custom template display_mode_X.htt] Hint: 99:cheat sheet with ALL Anynews placeholders available in the template files

  • start_news_item: start showing news from the Nth news item onwards (Note: -1: last item, -2: 2nd last etc.) [valid: -999..999]

  • max_news_items: max. number of news entries to show
    [valid: 1..999]

  • max_news_length: max. news length to be shown
    [-1:= full length]

  • strip_tags: flag to strip tags from news short/long text not contained in allowed_tags [true:strip tags, false:don't strip tags]

  • allowed_tags: tags to keep if strip_tags = true [default: '<p><a><img>']

  • custom_placeholder: create own placeholders for usage in template files
    Example: custom_placeholder = array('MY_IMG' => '%img%', 'MY_TAG' => '%author%', 'MY_REGEX' => '#(test)#i')

    Stores all image URLs, all text inside <author></author> tags and all matches of "test" in placeholders: {PREFIX_MY_IMG_#}, {PREFIX_MY_TAG_#}, {PREFIX_MY_REGEX_#}, where PREFIX is either "SHORT" or "LONG", depending if the match was found in the short/long news text and # is a number between 1 and the number of matches found

  • sort_by: defines the sort criteria for the news items returned
    [1:position, 2:posted_when, 3:published_when, 4:random order, 5:number of comments]

  • sort_order: defines the sort order of the returned news items
    [1:descending, 2:=ascending]

  • not_older_than: skips all news items which are older than X days
    [0:don't skip news items, 0...999: skip news items older than x days (hint: 0.5 --> 12 hours)]

  • lang_id: defines Anynews language file to be used [allowed: 'AUTO', or a valid WB language file flag: 'DE', 'EN', ...]

  • lang_filter: flag to enable language filter (requires a language flag in page URL like [default:= false, true:=only show news, which page language match given $lang_id]

Tip: To output news title and all possible Anynews group_type_ids (post_id, section_id, page_id, group_id), add the following code into a page/section of type code.

require_once(WB_PATH . '/modules/cwsoft-anynews/code/anynews_functions.php');
getGroupIdTypes($sort_column = "post_id",
 $sort_order = "ASC",
 $output = true);

Then visit the created page/section in your frontend and extract the group_tpye_ids you want to use in your Anynews function call.

Anynews Templates

The HTML skeleton of the Anynews output is defined by template files display_mode_X.htt stored in the Anynews subfolder templates. The template file used is defined by the Anynews function parameter $display_mode, which defaults to 1 if no valid input is defined. To create your own Anynews template, create a new file in the Anynews template folder and rename it to templates/display_mode_5.htt. You can use the cwsoft-addon-file-editor to create and edit this file via the WBCE backend.

Step 1:

Add the HTML skeleton below to your custom template file. All Anynews output should be wrapped in a div with class "mod_anynews" to prevent CSS clashes with other modules, templates or the WBCE core.

<div class="mod_anynews">
    <h1>Anynews Header (shown only once)</h1>

    <!-- next three lines will be repeated for each existing news entry -->
    <h2>News Title (repeated for each news item)</h2>
    <p>Dummy news text </p>

    <!-- this line should only show up if no news item exists -->
    <p>No news available yet</p>

Step 2:

Now we add control statements for the template parser Twig used by Anynews. The line {% for news in newsItems %} loops over all news defined in the variable newsItems created by Anynews. The line {% if news.TS_POSTED_WHEN > 0 %} prevents that news just created but not yet saved are listed. Inside the loop, news data extracted from the news module is accessible from the variable news created by Twig. Outputs enclosed in {% else %} and {% endfor %} is only displayed if no news exist at all.

<div class="mod_anynews">
    <h1>Anynews Header (shown only once)</h1>

    {% for news in newsItems %}        
        {% if news.TS_POSTED_WHEN > 0 %}
            <h2>News Title (repeated for each news item)</h2>
            <p>Dummy news text </p>
        {% endif %}

    {% else %}
        <p>No news available yet</p>
    {% endfor %}

Step 3:

Finally we replace the dummy text with placeholders provided by cwsoft-anynews. Data from the news module is stored in the placeholder newsItems. Text outputs from Anynews language files is stored in the placeholder lang. Review the template file display_mode_99.htt (cheat sheet) to get a list of all available Anynews placeholders. Remember to wrap your placeholders with double currly brackets {{ placeholder }}.

<div class="mod_anynews">
    <h1>{{ lang.TXT_HEADER }}</h1>

    {% for news in newsItems %}
        {% if news.TS_POSTED_WHEN > 0 %}
            <h2>{{ news.TITLE }}</h2>
            {{ news.CONTENT_LONG }}
        {% endif %}

    {% else %}
        <p>{{ lang.TXT_NO_NEWS }}</p>
    {% endfor %}

If you want to create a custom template with jQuery effects, look at the template files display_mode_3.htt and display_mode_4.htt, which implement 3rd party jQuery sliding effects. To learn more about the possibilities of the template parser Twig, please have a look at the excellent Twig user manual.

Anynews CSS

The Anynews default templates (/templates/display_mode_X.htt) wrap the Anynews output in a div container as shown below.

<div class="mod_anynews">
    <h2>Dummy Header</h2>
    <p>Dummy news text to explain</p>

To change the news header of aboves example to green and the news text to blue, open the css/anynews.css file in the cwsoft-addon-file-editor and add the following CSS definitions.

div.mod_anynews h2 {
    color: green;

div.mod_anynews p {
    color: blue;

Note: It is common practice to limit the scope of the CSS defintions to the div mod_anynews. This practice ensures that your CSS definitions do not overwrite styles defined in other modules, templates or the WBCE core. You should stick to this good practice when creating your own template files.

Known Issues

You can track the status of known issues or report new issues found in cwsoft-anynews via GitHubs issue tracking service. If you run into any issues with Anynews, please visit this page first and check if this issue is already known.


If you have questions or issues with Anynews, please visit the WBCE Forum and ask for help.

Always provide the following information with your support request:

  • detailed error description (what happens, what have you already tried ...)
  • the Anynews version (go to WBCE section Add-ons / Info / Anynews)
  • your PHP version (use phpinfo(); or ask your provider if in doubt)
  • WBCE version, Service Pack number and build number of your version
  • name of the WBCE frontent template used (e.g. round, allcss ...)
  • information about your operating system (e.g. Windows, Mac, Linux) incl. version
  • information of your browser and browser version used
  • information about changes you made to WBCE (if any)