Code Snippet: Display news items, anywhere

BlackBird

Yesterday, I was asked for a solution to show the group image with AnyNews. So I created this solution:

File include.php, find line 256 ff:


                               // replace the news article dependend template placeholders
$tpl->set_var(array(
'WB_URL'    => WB_URL,
...more code going here...


BEFORE, add:


       $group_id = $row['group_id'];
       $image = '';
       if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg'))
       {
           $image = '<img src="'.WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg'.'" alt="" />';
       }


AFTER, add:


'GROUP_IMAGE'     => $image,


Add the {GROUP_IMAGE} markup to the template (.htt file) you're using and you're done.

Edit: You may edit the <img> attribute to suit your needs. (Add a CSS class or something.)
[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]

kleo

Quote from: Argos on June 14, 2010, 01:11:53 PM
Quote from: kleo on January 25, 2010, 07:42:48 PM
I have more pages (and sections) with the module News. But I use not Groups by News module.

How can I use Anynews to display newsitems from certain pages or section?
How can I change the code?

Earlier in this thread VotreEspace posted an excellent solution for section_ID support: https://forum.websitebaker.org/index.php/topic,409.msg95799/topicseen.html#msg95799

Thank YOU!
I think this feature should be added as a built-in option to the module!

I use now a Droplett:
http://www.websitebakers.com/pages/droplets/official-library/navigation/getnewsheads.php

Can you help me to change this droplett with this code?
From your Link:
https://forum.websitebaker.org/index.php/topic,409.msg95799/topicseen.html#msg95799

Argos

Quote from: kleo on January 25, 2010, 07:42:48 PM
I have more pages (and sections) with the module News. But I use not Groups by News module.

How can I use Anynews to display newsitems from certain pages or section?
How can I change the code?

Earlier in this thread VotreEspace posted an excellent solution for section_ID support: https://forum.websitebaker.org/index.php/topic,409.msg95799/topicseen.html#msg95799

I think this feature should be added as a built-in option to the module!
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

snark

If i put two anynews snippets on one page, both with the coda slider something goes wrong

when click the arrow on one anynews block, both will slide to the next item

is it possible to prevent this?



syamfamily

hello guys...how the way to add group image in anynews?
does anyone know.....please help me....

:mrgreen: :mrgreen: :mrgreen:

Harry P.

Thanks for the info, doc.

Quotea "standalone" tool (PHP 5.3) with more flexibility

Is that one publicly available?

doc

#471
Hi,

Quote from: Harry P.After the Add-On File editor, the next suspension.
Last reported AFE "issue" goes back to 25th July 2009 (Englisch thread). Last "feature request" goes back to 2009.

Some "non AFE related issues" were reported after introduction of WB 2.8.1 RC. Instead of waiting for WB 2.8.1 final to fix the problem, I decided to release an intermediate AFE version, which also fixed some "depracated warnings". In my eyes, AFE reached a "mature" level with v0.80.

As maintainance without specific requests or bug reports from the community is not very attractive to me, I decided to stop my support. Some open requests, like the possibility to edit not only WB files, would have broken my "philosophy" behind AFE and wouldn´t have made it into AFE anyway (which may change with another maintainer). There was nothing I could think off to be added to AFE in the WB 2.x line anyway

That´s basically all I have to say about this topic in the forum :-)

P.S:
However, the experience I gained is transferred into a "standalone" tool (PHP 5.3) with more flexibility (e.g. folder based navigation, definition of any folder you like), more configuration options such as filter, search and basic image transformation (crop, resize, rotate, flip).

BlackBird

Of course, there is a reason, but I don't think that this should be discussed here. :roll: Maybe it helps if I mention that I also have left all WB teams.

Edit: BlackBird = WebBird. My old Forum account was deleted.
[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]

Harry P.

After the Add-On File editor, the next suspension.

Is there any particular reason? Did I miss something "political"?

Did I even bet on the wrong horse by picking WBfor some major projects?  :roll:

I hope not...

WebBird

Please note that I have suspended my support for the "Anynews" code snippet effective March 24, 2010.

If someone wants to develop or maintain this code snippet any further, please feel free to do so, but keep in mind  that the module is licensed under GNU GPL.

The last stable version of the module can be found on the WebsiteBaker Addons Repository.

http://www.websitebakers.com/pages/code-snippets/listings/anynews.php

Regards, Bianka (WebBird)

sky writer

Your array solution worked perfectly.  Thanks again.  I would send chocolate, but if you're anything like my wife who is Dutch, you prefer the GOOD chocolate to our Canadian MILK variety.  :lol:

WebBird

Quote from: sky writer on March 23, 2010, 05:05:31 PM
I really appreciate your time and knowledge.

Well, I like chocolate very much. :-D

sky writer

Thank you so much!  The array approach looks like what I will be needing.  I really appreciate your time and knowledge.

WebBird

You would have to use variables, depending on the page, and use a default (random, in this case) for all pages that don't have a special setting.

So, this is the default, as quoted in the help page:


<?php displayNewsItems(
   
$group_id 0,
   
$max_news_items 10,
   
$max_news_lenght = -1,
   
$display_mode 1,
   
$lang_id 'auto',
   
$strip_tags true,
   
$allowed_tags '<p><a><img>',
   
$custom_placeholder false,
   
$sort_by 1,
   
$sort_order 1,
   
$not_older_than 0
   
); 
?>



For "3 random News from all groups" you need to set $group_id to 0, $max_news_items to 3 and $sort_by to 4.

Now let's say that this is the default for all pages with no special settings, but on page "About", you would like to see 3 random News from Group 5. Let's assume that the "About" page has the ID 55.


<?php
$this_group_id 
0;
if ( 
PAGE_ID == 55 ) {
    
$this_group_id 5;
}

displayNewsItems(
   
$group_id $this_group_id,
   
$max_news_items 3,
   
$max_news_lenght = -1,
   
$display_mode 1,
   
$lang_id 'auto',
   
$strip_tags true,
   
$allowed_tags '<p><a><img>',
   
$custom_placeholder false,
   
$sort_by 4,
   
$sort_order 1,
   
$not_older_than 0
   
); 
?>




If you have lot's of pages with different settings, it will be easier to use an array instead.


<?php
$map_page_to_group 
= array(
    
55 => 5,
    
66 => 6,
);

$this_group_id = isset( $map_page_to_group[PAGE_ID] ) ? $map_page_to_group[PAGE_ID] : 0;

displayNewsItems(
   
$group_id $this_group_id,
   
$max_news_items 3,
   
$max_news_lenght = -1,
   
$display_mode 1,
   
$lang_id 'auto',
   
$strip_tags true,
   
$allowed_tags '<p><a><img>',
   
$custom_placeholder false,
   
$sort_by 4,
   
$sort_order 1,
   
$not_older_than 0
   
); 
?>




Edit: Put this code into your index.php.

sky writer

I'll try to explain by giving an example.

Let's say I only have three pages (Home, About and Contact), and three news groups (A,B and C).  And I have a right hand column block on all the pages, which is where I want the anynews to display.

On the "Home" and "Contact" pages, I want to show three random news posts, chosen from all three groups (A, B and C).  But on the "About" page, I want to show three random news posts ONLY from Group C.

Currently I have the anynews call in my template index.php, and so I get three random posts pulled from all my groups.  I realize that I can put anynews in a code section on each individual, but in reality I have dozens of pages, and most of them I want to have the same call (random from all groups).  There are only about four pages that I want to have specific info from only one group called.

So, I am wondering if you can have a "global" anynews call in the template index.php, and then somehow over-ride it on certain pages with a 'code section call' on those pages.

Hope this makes more sense.

WebBird

I don't know if I understand you right. You wish to include AnyNews only once, but show the content of different News Sections and/or Groups depending on the current page?

sky writer

I've tried searching the forum and this thread, but can't find an answer.

I have a block in my template that currently shows three random news items (from 5 groups).  The anynews code is in my index.php

Is it possible to have anynews show different content (from a single group) in this same block on certain pages?  I know I can add another block and call anynews from a code section, but then the three "global" anynews items AND these specific items would show.  I only want to show the specific anynews items on these pages.

I am trying to avoid having to add an anynews code section for every single page in my site.

tiesy

Quote from: kleo on January 25, 2010, 07:42:48 PM
I have more pages (and sections) with the module News. But I use not Groups by News module.

How can I use Anynews to display newsitems from certain pages or section?
How can I change the code?

More thanks!



This is easy to solve: You have to relace "$group_id" to "$page_id" on every position of the snippet. Tools like "InfoRapid Suchen & Ersetzen" will do this in a few seconds. If you don´t want to overwrite the original-snippet, simply rename it in the info.php to something like "anypagenews". 

WebBird

Ah. I misunderstood "resulting page". You meant the page Anynews links to, right? You can open a bug ticket for the news module if you wish. But take a look if it is an already known problem before opening a ticket.

seagull

@WebBird

QuoteMaybe i overlooked it, but when i use displayanynews with displaymode=2(only the newstitle as link) and having newsitems with only shorttext the resulting page displays the longtext wich is empty, so only the header and the footer are displayed.
Am i doing something wrong or is this the way the snippet should work?(only with long text)

It's not Anynews that causing this but the newsmodule itself.

For now i modified view.php(at line 450) of the news so that if the $post_long is empty the $post_short is printed otherwise the $post_long should be printed.

thanks, Jan

Harry P.

Ah, now it's working. Thanks a lot, WebBird!

WebBird

Woops, sorry, it's ob_get_clean(), not ob_end_clean().

Harry P.

Thanks! But...

I copied your code 1:1 to a droplet, but when used on a page, it doesn't return anything.... :?

WebBird

#454
Try:



$output = NULL;
if (function_exists('displayNewsItems')) {
  ob_start();
  displayNewsItems(
      $group_id = 2,
      $max_news_items = 10,
      $max_news_length = -1,
      $display_mode = 1,
      $lang_id = 'auto',
      $strip_tags = true,
      $allowed_tags = '<p><a><img>',
      $custom_placeholder = false,
      $sort_by = 1,
      $sort_order = 1,
      $not_older_than = 0
  );
  $output = ob_get_clean();
}
return $output;



You may set $output to something else but NULL, if you wish to print out an error message if the Anynews call fails, for example.

Edit: Fixed code.

WebBird

You will have to "catch" the output with ob_start()... etc and return it.