Author Topic: Code Snippet: Display news items, anywhere  (Read 258521 times)

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #450 on: February 01, 2010, 10:33:39 AM »
Do you use "return" to return the content, or just the call? The call does an "echo", what's not what you're after when using a droplet.

Harry P.

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #451 on: February 01, 2010, 10:38:28 AM »
Just the call, as shown in my code quote.

What would the droplet syntax look like with a return?

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #452 on: February 01, 2010, 10:41:29 AM »
You will have to "catch" the output with ob_start()... etc and return it.

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #453 on: February 01, 2010, 10:45:50 AM »
Try:

Code: [Select]

$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.
« Last Edit: February 01, 2010, 11:17:52 AM by WebBird »

Harry P.

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #454 on: February 01, 2010, 11:01:49 AM »
Thanks! But...

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

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #455 on: February 01, 2010, 11:16:49 AM »
Woops, sorry, it's ob_get_clean(), not ob_end_clean().

Harry P.

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #456 on: February 01, 2010, 11:23:59 AM »
Ah, now it's working. Thanks a lot, WebBird!

Offline seagull

  • Posts: 79
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #457 on: February 01, 2010, 09:03:55 PM »
@WebBird

Quote
Maybe 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

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #458 on: February 02, 2010, 10:00:13 AM »
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.

Offline tiesy

  • Posts: 125
    • Wir in Wallenhorst
Re: Code Snippet: Display news items, anywhere
« Reply #459 on: February 02, 2010, 05:32:41 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". 

Offline sky writer

  • Posts: 926
Re: Code Snippet: Display news items, anywhere
« Reply #460 on: March 22, 2010, 02:43:24 AM »
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.

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #461 on: March 22, 2010, 11:18:12 AM »
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?

Offline sky writer

  • Posts: 926
Re: Code Snippet: Display news items, anywhere
« Reply #462 on: March 22, 2010, 04:32:03 PM »
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

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #463 on: March 23, 2010, 10:11:18 AM »
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:

Code: [Select]
<?php displayNewsItems(
   
$group_id 0,
   
$max_news_items 10,
   
$max_news_lenght = -1,
   
$display_mode 1,
   
$lang_id = &#39;auto&#39;,
   
$strip_tags true,
   
$allowed_tags = &#39;<p><a><img>&#39;,
   
$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.

Code: [Select]
<?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 = &#39;auto&#39;,
   
$strip_tags true,
   
$allowed_tags = &#39;<p><a><img>&#39;,
   
$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.

Code: [Select]
<?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 = &#39;auto&#39;,
   
$strip_tags true,
   
$allowed_tags = &#39;<p><a><img>&#39;,
   
$custom_placeholder false,
   
$sort_by 4,
   
$sort_order 1,
   
$not_older_than 0
   
); 
?>



Edit: Put this code into your index.php.

Offline sky writer

  • Posts: 926
Re: Code Snippet: Display news items, anywhere
« Reply #464 on: March 23, 2010, 05:05:31 PM »
Thank you so much!  The array approach looks like what I will be needing.  I really appreciate your time and knowledge.

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #465 on: March 23, 2010, 05:55:59 PM »
I really appreciate your time and knowledge.

Well, I like chocolate very much. :-D

Offline sky writer

  • Posts: 926
Re: Code Snippet: Display news items, anywhere
« Reply #466 on: March 24, 2010, 03:08:37 AM »
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

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #467 on: March 24, 2010, 10:56:27 AM »
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)

Harry P.

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #468 on: March 26, 2010, 09:42:31 AM »
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...

Offline BlackBird

  • Posts: 2573
Re: Code Snippet: Display news items, anywhere
« Reply #469 on: March 26, 2010, 11:23:00 AM »
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.

doc

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #470 on: March 26, 2010, 03:07:24 PM »
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).
« Last Edit: March 26, 2010, 03:39:47 PM by doc »

Harry P.

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #471 on: March 26, 2010, 04:17:10 PM »
Thanks for the info, doc.

Quote
a "standalone" tool (PHP 5.3) with more flexibility

Is that one publicly available?

Offline syamfamily

  • Posts: 12
Re: Code Snippet: Display news items, anywhere
« Reply #472 on: May 14, 2010, 05:58:04 AM »
hello guys...how the way to add group image in anynews?
does anyone know.....please help me....

 :mrgreen: :mrgreen: :mrgreen:

snark

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #473 on: May 28, 2010, 12:30:44 PM »
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?



Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Code Snippet: Display news items, anywhere
« Reply #474 on: June 14, 2010, 01:11:53 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!

 

postern-length