Code Snippet: Display news items, anywhere

doc

Hi,

did a quick Google search and found some working code examples (within the first 10 matches or so).

Doc


WebBird

This is much more effort I can find the time for at the moment. :roll:

tiesy

Hi WebBird,
I have tested your include.php an it works as you explained. Many thanks for that.
It´s better than before, but not a real solution for the problem. Now it cuts all news-entries even if to long html-commands found in only one news-entry.

I don´t know how to make it, but the anynews-function "max_news_length" should not count the characters of html-tags and not replace the brackets in principle.

WebBird

#374
I also found that it is ... uhm ... "not nice" if there are any opening HTML tags in the remaining text, so I worked on a solution to close these tags, too. I'm not very happy with the code, but if it works, it's better than leaving it as is.

Can someone please do some tests with the include.php attached?

Edit: Removed attachment

WebBird

Ah. This also explains the problem "micklan" has with ’. Funny that I can't reproduce it... I'll try to find a solution. Thank you very much Aldus!!!

aldus

Hello

As far as i can reproduce this bug it has to do within the max-char restriction, e.g. 200 chars,
in the short-message as the function "wordwrap2" converts htmlentities ... so the brakets became
"<" and ">" - also the quotes to &quote ...

To avoid this i've add

<?php
 $restore 
= array (
    
'&lt;' => "<",
    
'&gt;' => ">",
    
'&quote;' => "\""
);
$temp[0] = str_replace(array_keys($restore), array_values($restore), $temp[0]);
?>


to the function "wordwrap2" in the bottom of the include.php,
but i'm pretty sure that were are more elegant ways to solve this.

Kind regards
Aldus


[gelöscht durch Administrator]

WebBird

Yes, I'd say it's the most probable explanation. Anyway, I don't know what to look for. :|

tiesy

It makes no difference, if I change the parameter from true to false. Language in quotes or not is all the same. I think it has to do with the server-setup.

WebBird

Well, on the screenshot the strip_tags param is set to true, which means "strip all tags", and the lang_id is still not enclosed in quotes. ;)

tiesy

Hi WebBird,

no, I can´t for the moment, it´s not public yet. But I made some screenshots, where you can see, what happens.


[gelöscht durch Administrator]

doc

@joep:
You can define all groups ($group_id = 0), a single group ($group_id = x) or a collection of groups ($group_id = array(3,4)). Details about the possible function parameters are provided in the Readme file of the module. A function call with two groups can be found in section "Example for a customized call:" of the Readme.

Please make sure you are using the latest version of anynews.

Doc

joep

My question is.

Is it possible to use multiple groups. for example group 3 and 4.
I have 8 groups.
7 of them i want to use.

Maybe i can use somkind of array??

WebBird

Quote from: tiesy on September 15, 2009, 09:47:36 AM
Yes, I´ve made no changes in the html-code on news-section. It´s a fresh wb-installation. The php-version is 4.3.9.
I know, that php5 is required for wb 2.8., but exept of anynews it works without any problems.

I've tried with PHP 4.4.9, but I still can't reproduce the error. Can you show us?

WebBird

Yes, it works only for one group. (Or use 0 for "get from all groups".)

What is the question? :roll:

joep

I have a question.

I use this code:
displayNewsItems(array(10,11, 12, 13, 14), 5, 0, 0, false);
I don't know much abouth anynews yet!!

What i trie to achief is a block with new items from several groups, showing only the title of the post.

So not the date, or the dots on the bottom. And not the title (Latest News).

It worked with this code:
$group = 9; // Specify the Group(id) you want to read the news from

global $database;

$query = "SELECT post_id,title,group_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = $group ORDER BY position DESC LIMIT 0, 3;";

/*This limits the results to max 5, so if you want it to be 10, make it LIMIT 0, 10. The first number defines the starting point, and the second the max/end of the results */

$error = mysql_error();
if (!$result = mysql_query($query)) {
  print "$error";
  exit;
}

while($data = mysql_fetch_object($result)){
  $title = $data->title;
  $id = $data->post_id;
  $link = $data->link;
  echo '<li><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a>'.$short.'</li>'; // the loop

}
echo "</ul>"; // end of the loop


the problem with this code is that it only works with one group.

the link to my page is :
http://www.studiozi.com/wb

Thanq in advanced




tiesy

Yes, I´ve made no changes in the html-code on news-section. It´s a fresh wb-installation. The php-version is 4.3.9.
I know, that php5 is required for wb 2.8., but exept of anynews it works without any problems.

WebBird

Quote from: tiesy on September 11, 2009, 05:56:44 PM
Could it have something to do with the installed php-version?

Which is...?

Is the HTML correct on the News page itself?

tiesy

Hi Doc & WebBird,

thanks for your help. I´ve tested your solutions, changed true to false, but the problem stays on. Could it have something to do with the installed php-version?

doc

Hi,

maybe consider to write your anynews function calls as follows (helps to keep track of the various parameters).

<?php
if (function_exists('displayNewsItems')) {
   
displayNewsItems($group_id 2
      
$max_news_items 2$max_news_length 200
      
$display_mode 5$lang_id 'DE',
      
$strip_tags false$allowed_tags '<p><a><img>'
      
$custom_placeholder false
      
$sort_by 4$sort_order 1$not_older_than 0
   
);
}
?>


You should check $display_mode (5 uses a custom template) and the last two parameters.

Doc

WebBird

Cannot reproduce this error. Use "false" instead of "true" and wrap DE in quotes, please.


if (function_exists('displayNewsItems')) {
   displayNewsItems(2, 2, 200, 5, 'DE', false,'<p><a><img>', 1, 0);
}


Also, you use a custom template, so please try to replace 5 with 1 for testing. (Which means "details".)

tiesy

Hi WebBird!

Yes, I did. This is my snippet in a code-section:

if (function_exists('displayNewsItems')) {
   displayNewsItems(2, 2, 200, 5, DE, true,'<p><a><img>', 1, 0);
}

I also tried "false" instead of "true". The problem is the same.

Do you see any mistake?

WebBird

Have you tried the 'strip_tags' and 'allowed_tags' options of the displayNewsItems() method?


strip_tags...         true:=remove tags from short and long text (default:=true); false:=don´t strip tags
allowed_tags...        tags not striped off (default:='<p><a><img>')


See included help files for details.

tiesy

I´ve a problem with allowed tags and didn´t find a solution:

The tag-brackets (<,>) will be replaced with "&lt;" or "&gt;". So, if I allow some tags, the sourcecode is shown in the output.

I use wb2.8 and the newest version of anynews.

micklan

#354
Hi!

Why i receive the "&rsquo;" syntax in news instead of  " ' " character ?

Thanks you!

snark

Anyone who knows wether I can use the anynews for the mediablog module