Code Snippet: Display news items, anywhere

Harry P.

Just the call, as shown in my code quote.

What would the droplet syntax look like with a return?

WebBird

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.

Hello All,

when I use the AnyNews call...


if (function_exists('displayNewsItems')) {
  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
  );
}


... on a standalone CODE page, News teasers display fine within my template.

But when I pack the same into a droplet, say "Anynews", and place it on a WYSIWYG page with [Anynews]], the News teasers appear outside (above) my WB template.

Any idea what I'm missing? I walked through this whole thread but couldn't find a clue...  :?

WebBird

Great, Jan, thank you! Just take the help_en.html to see what's new there and missing in help_nl.html.

I'll take a look at displaymode 2 tomorrow. Promise. :-D

seagull

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)

@webbird, i would like to help you with the Dutch translation.

Jan

WebBird

Yepp. Will write that on my Todo list. But I need help with the NL readme. :roll:

doc

@Webbird: Would be nice if you could also maintain/update the README file with new releases. The latest implemented options seems to be missing. Also the README on AMASP and Add-ons point to an outdated version.

Regards Doc

Turskis

Now it's working. Thanks, this was a very important feature for me!

WebBird

#444
It is already set in the new include.php. But maybe I did not upload the last version. :?

Please download the new version 1.15 at AMASP and try it again.

http://www.websitebakers.com/media/amasp_uploads/anynews_v1.15.zip

Edit: Checked it out, it was missing in the include.php I provided for testing. I'm sorry. :|

Turskis

No help. I think that variable {COMMENTS} is not set anywhere. Do I need some custom placeholder? Or does it need to be set in include.php. Or am I totally lost here?

WebBird

Hm. Works for me. :?

Just saw that the text is outside the loop. Try this:


<div class="anynews">
<h2>{TXT_HEADER}</h2>
<!-- BEGIN news_block -->
<p><strong>{TITLE} {POSTED_WHEN}</strong></p>
Number of comments: {COMMENTS}<br />
{CONTENT_SHORT}
<!-- BEGIN readmore_link_block -->
<p><a href="{LINK}">{TXT_READMORE}</a></p>
<!-- END readmore_link_block -->
<hr />
<!-- END news_block -->
</div>

Turskis

Tried that, but it is not displaying the number. Only "Number of comments: " and then blank

WebBird

Maybe this helps...

If you do not set $display_mode, the default is 'detailed output'. The template file for 'detailed output' is htt/detailed_output.htt.

Here's the content of that file:


<div class="anynews">
<h2>{TXT_HEADER}</h2>

<!-- BEGIN news_block -->
<p><strong>{TITLE} {POSTED_WHEN}</strong></p>
{CONTENT_SHORT}
<!-- BEGIN readmore_link_block -->
<p><a href="{LINK}">{TXT_READMORE}</a></p>
<!-- END readmore_link_block -->
<hr />
<!-- END news_block -->
</div>


Just add the markup {COMMENTS} to that file. Example:


<div class="anynews">
<h2>{TXT_HEADER}</h2>
Number of comments: {COMMENTS}<br />
<!-- BEGIN news_block -->
<p><strong>{TITLE} {POSTED_WHEN}</strong></p>
{CONTENT_SHORT}
<!-- BEGIN readmore_link_block -->
<p><a href="{LINK}">{TXT_READMORE}</a></p>
<!-- END readmore_link_block -->
<hr />
<!-- END news_block -->
</div>

WebBird

Do you USE that template? (Param $display_mode in displayNewsItems call.)

Turskis

Not working. Do I need to add some custom placeholder also?

I tried adding <tt>COMMENTS: </tt>{COMMENTS}<br /> in custom_output_display_mode_4.htt

WebBird

Just add {COMMENTS} to the template you use at the position you wish.

Turskis

Just can't understand how to add number of comments to custom templates  :oops:

WebBird

Quote from: Turskis on January 27, 2010, 08:34:13 PM
Seems to work. It would be good to display number of comments after the date in news list.

I thought you would suggest this. Try COMMENTS markup. ;) (Custom Template)

Turskis

Seems to work. It would be good to display number of comments after the date in news list.

WebBird

#433
Please try the include.php attached. Be sure to make a backup copy of the original include.php before trying this one.

Edit: Removed attachment. New version available at AMASP. http://www.websitebakers.com/pages/code-snippets/listings/anynews.php

WebBird

Hmmm... This requires a more complex SQL query, as the comments are stored in another table. You will have to modify the query (lines 127ff), or add another one especially for the comments count.

Are there any other ones interested in this feature?

Turskis

I've been asking about possibility to view the posts in "most commented" order:

https://forum.WebsiteBaker.org/index.php/topic,16548.0.html

I quess this is possible with Anynews, by modifying include.php. My coding skills are limited, so could somebody give me a hint?

sort_by...    5:= number of comments

kleo

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!


aldus

Hm ...
I've update the modul "informati0n" at AMASP to leave html-source inside a
pre tag uninterpreted, e.g.

<pre class="code">
&#x3c;ul id="myGallery" class="image-overlay">
&#x3c;li>
&#x3c;a href="http://www.domain.tld">
      &#x3c;img alt="Image 1" src="yourimages/Image1.jpg"/>
      &#x3c;div class="caption">
        &#x3c;h3>My Image&#x3c;/h3>
        &#x3c;p>click for more info&#x3c;/p>
      &#x3c;/div>
    &#x3c;/a>
  &#x3c;/li>
&#x3c;/ul>
</pre>


by replacing the opening braked < to his hex-entity &#x3c; .
So you can (now) display source inside the description/information fields
like shown at
http://www.websitebakers.com/pages/code-snippets/various/image-overlay.php

Also replaced the $ char to avoid PHP-Conflicts in examples, like "var $xyz is not defined" ...

Regards
Aldus

erpe0812

@all who are interested in this:
https://forum.websitebaker.org/index.php/topic,409.msg110386.html#msg110386

It was a bug in xfast_Template_2 and had nothing to do with anynews.........though it seems to have on the first impression.

Thanks to Webbird and Aldus for quick help.

rgds

erpe