Code Snippet: Display news items, anywhere

bikerider


aldus

Hello bikerider

I'm pretty sure that there are error-messages if you try to set the PHP-Error-Reporting-Level to "E_ALL".

Some copy and paste errors, as the function is named "displayNewsItems" ..


<?php 
if(function_exists('displayNewsItems')) {
    
displayNewsItems05501"""mehr lesen""aktuell gibt es keine news..."false);
} else {
    echo 
'Requires code snippet anynews (WB addons repository) to display news here.';
}
?>




Regards
Aldus

bikerider

hm, that brings up another problem. when I use the function display_news_item (which is of course not working anymore) the snippet [[RandomImage?dir=header]] works fine.
But when I use the function displayNewsItem I have a problem with the [[RandomImage?dir=header]]-Snippet:  the pictures aren't shown anymore instead the function is displayed as "[[RandomImage?dir=header]] ". What's the problem here? anybody else has that?
And by the way: the news-portlet stays empty: http://www.bikeride.ch/wb/pages/events.php

Code of template: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
<?php page_title(); ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php if(defined('DEFAULT_CHARSET')) { echo DEFAULT_CHARSET; } else { echo 'utf-8'; }?>" />
<meta name="description" content="<?php page_description(); ?>" />
<meta name="keywords" content="<?php page_keywords(); ?>" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="<?php echo TEMPLATE_DIR?>/layout4_setup.css" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="<?php echo TEMPLATE_DIR?>/layout4_text.css" />
<title>Multiflex-3 Update-2 / Overview</title>
</head>
<!-- Global IE fix to avoid layout crash when single word size wider than column width -->
<!--[if IE]><style type="text/css"> body {word-wrap: break-word;}</style><![endif]-->
<body>
<body>
<!-- Main Page Container -->
<div class="page-container">
<!-- For alternative headers START PASTE here -->
<!-- A. HEADER -->
<div class="header">
       <div class="nav2">
      <!-- Navigation item -->
<?php if(SHOW_MENU) { /* Only shown menu if we need to */ ?>
    <?php show_menu2(0SM2_ROOTSM2_STARTSM2_PRETTY'<li [if(class==menu-current){id="menu-current"}]>[a]<span>[menu_title]</span></a>'); ?>
    <?php ?>
    </div><!-- A.2 HEADER MIDDLE -->
  <div class="header-middle">
     [[RandomImage?dir=header]]
    <!-- Site message -->
    <div class="sitemessage"> </div>
  </div>
  <!-- A.3 HEADER BOTTOM -->
  <div class="header-bottom">

  </div>
  <div class="header-breadcrumbs">

  </div>
  <!-- B. MAIN -->
  <div class="main">
    <!-- B.1 MAIN NAVIGATION -->
    <div class="main-navigation">
      <!-- Navigation Level 3 -->
      <div class="round-border-topright"></div>
     <h1 class="first">Men&uuml;</h1>
      <!-- Navigation with grid style -->
     <?php show_menu2(0,      SM2_ROOT+1SM2_CURR+1SM2_PRETTY'<dt>[a][menu_title]</a>''</dt>''<dl class="nav3-grid">' '</dl>');?>
     
    </div>
    <!-- B.2 MAIN CONTENT -->
    <div class="main-content">
      <!-- Pagetitle -->
      <h1 class="pagetitle"><?php echo PAGE_TITLE?></h1>
      <!-- Content unit - One column -->
      <div class="column1-unit">
             <?php page_content(); ?>
      </div>
    </div>
    <!-- B.3 SUBCONTENT -->
    <div class="main-subcontent">
      <!-- Subcontent unit -->
      <div class="subcontent-unit-border-orange">
        <div class="round-border-topleft"></div>
        <div class="round-border-topright"></div>
        <h1 class="orange">latest news</h1>
       <?php 
        
if(function_exists('displayNewsItems')) {
          
display_news_items(05501"""mehr lesen""aktuell gibt es keine news..."false);
        } else {
          echo 
'Requires code snippet anynews (WB addons repository) to display news here.';
        }
      
?>

      </div>
    </div>
  </div>
  <!-- C. FOOTER AREA -->
  <div class="footer">
    <p><?php page_footer(); ?></p>
  </div>
</div>
</body>
</html>


:?

bikerider

that's it - didn't remark that...  :oops:

thank you very much!!

doc

Hi,

if you are using the latest version of Anynews from the WB Repository, you need to adapt your code as the Function call has changed from: display_news_items to displayNewsItems. So simply replace the two strings in your code and it should work.

This is also the right order of function parameters (flags) are described in the README file distributed with Anynews.

Doc

bikerider

Hi folks,
It seems that I have a very stupid question - but I didn't find anyone with the same problem. I've got this anynews-snippet
<?php 
        
if(function_exists('display_news_items')) {
          
display_news_items(05501"""mehr lesen""aktuell gibt es keine news..."false);
        } else {
          echo 
'Requires code snippet anynews (WB addons repository) to display news here.';
        }
      
?>

and I have news - called (you won't belive it) news. But what ever I do - the only thing shown is: "Requires code snippet anynews (WB addons repository) to display news here." Of course the Snippet is installed correctly as module. What's wrong here? Any Ideas? Language problems? The site is in german...

Thank you very much,
Patrick

Luckyluke

A solution is an extra parameter with the section-ID.
So you can choose the appropriate section according to the language you want.
I don't think this is a big adjustment? But a very good one.

Grtz,
Luc

kweitzel

It seems like only the newspage is missing that language. But anyway, from my understanding the language extraction should work anyway. I'll give it a try as well later on.

cheers

Klaus

Luckyluke

Quote from: erpe
you have to create a group for each language and then specificly call the group in the anynews call.
he language-file is for the readmore link and the date.

@Erpe,
This is a solution but not the best one.

Quote from: kweizel
Do you have the "language" in the URL exactly like in the anynews parameter and is it shown as well in the URL if you open the news page?

@Kweizel
I'm sorry, I don't understand what you mean.
But in WB 2.7 my site shows something like ?language=NL in the URL. I see it's gone after I update the site to WB 2.8
I updated the site with the news-module. In my new template I will use anynews with 3 languages.

Grtz,
Luc

kweitzel

Guys ... have a look at the last Version of the anynews snippet ... it parses the URL for the "language" like in the Tutorial Setup ... this way it should work.

@Luc: Do you have the "language" in the URL exactly like in the anynews parameter and is it shown as well in the URL if you open the news page?

cheers

Klaus

erpe0812

Hi Luc

you have to create a group for each language and then specificly call the group in the anynews call.
The language-file  is for the readmore link and the date.

rgds

erpe

Xagone

language is only for the template, not the language of the news.

it seams to me you'd need to take my last version of include and ad the news sections of each languages.
Xagone Inc. (formerly VotreEspace)
[url="http://xagone.com/"]http://xagone.com/[/url]

Luckyluke

Hi,

I've got a multi language site.
In the template I use following code:

<?php
if (function_exists('displayNewsItems'))  {
  if (
LANGUAGE == 'NL')  {
    
displayNewsItems(2,3,-1,1,'nl',true'<p><a><img>','none',43,'disabled');
  } else {
        
displayNewsItems(3,3,-1,1,'en',true'<p><a><img>','none',43,'disabled'); 
  }

?>


The language setting is enabled.
Still, I see all the news from all languages.
It's a bit the same problem like this here (on previous page) but it doesn't work in my situation. I use WB 2.8. Is this a WB 2.8 specific problem?

Grtz,
Luc

crnogorac081

If you  want do display specific news posts, find this lines and replace them with following code:


       /**
        * Work out SQL query for the group_id
        * $sql_group_id:= ($group_id:=0 => '1'; $group_id:=X => `group_id` = 'X'; $group_id:=array(2,3) => `group_id` IN ('2,3'))
        */
       // show all groups if group_id is array which contains 0
       if (is_array($group_id) && in_array(0, $group_id)) $group_id = 0;

       // check for multiple groups or single group values
       if (is_array($group_id)) {
           // SQL query for multiple groups
           $sql_group_id = '`post_id` IN (' . implode(',', $group_id) . ')';
       } else {
           // SQL query for single or empty groups
           $sql_group_id = ($group_id) ? '`post_id` = \'' . $group_id . '\'' : '1';
       }


this way you can put post id in array..

cheers
Web developer

Xagone

done it.

i've modified include.php of version 1.11 to make the function do this :
function displayNewsItems(
       $section_id = 0, $group_id = 0, $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)

see? first item is section....

i've also added this :
sanitizeUserInputs($section_id, 'i{0;0;999}');
just after the line with this
sanitizeUserInputs($group_id, 'i{0;0;999}');

i've added this :
// check for multiple sections or single section values
       if (is_array($section_id)) {
           // SQL query for multiple groups
           $sql_section_id = ' AND `section_id` IN (' . implode(',', $section_id) . ')';
       } else {
           // SQL query for single or empty groups
           $sql_section_id = ($section_id) ? 'AND `section_id` = \'' . $section_id . '\'' : '1';
       }

just after this code :
// show all groups if group_id is array which contains 0
       if (is_array($group_id) && in_array(0, $group_id)) $group_id = 0;

       // check for multiple groups or single group values
       if (is_array($group_id)) {
           // SQL query for multiple groups
           $sql_group_id = '`group_id` IN (' . implode(',', $group_id) . ')';
       } else {
           // SQL query for single or empty groups
           $sql_group_id = ($group_id) ? '`group_id` = \'' . $group_id . '\'' : '1';
       }

and finaly, modified the sql for this :
$sql = "SELECT * FROM `$table`
           WHERE `active` = '1'
           AND $sql_group_id
           $sql_section_id
           AND (`published_when` = '0' OR `published_when` <= '$server_time')
           AND (`published_until` = '0' OR `published_until` >= '$server_time')
           AND $sql_not_older_than
           ORDER BY $sql_order_by $sql_sort_order
           LIMIT 0, $max_news_items";


now i can specify the news i want to show it's in section "53", meaning the section of this particular page, so i dont have to make groups specific to show only this news and the 4 mores "news" modules in other section wont show on my anynews call.

p.s. : i've included a retranslation of the include.php and FR.php language, it wasn't completed.

[gelöscht durch Administrator]
Xagone Inc. (formerly VotreEspace)
[url="http://xagone.com/"]http://xagone.com/[/url]

Ruud

Every post also has a section_id (and page_id) stored in the table.

Adding a
WHERE `section_id` = $my_wanted_section_id
in the query is what you want.

$my_wanted_section_id should be added to the function parameterlist.

Ruud
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

crnogorac081

I dont understand, you want to display specific news from specific group ?

like:

Group 15
-News 1
- news 2    < this one
- news 3
- news 4    < and this one ?

right ?
Web developer

Xagone

i'll test, but as I can see, it will show ALL news, i want a particular news "section" from a singular "page" and not all news sections and pages
Xagone Inc. (formerly VotreEspace)
[url="http://xagone.com/"]http://xagone.com/[/url]

crnogorac081

You can remove:


       $table = TABLE_PREFIX . 'mod_news_posts';
       $sql = "SELECT * FROM `$table`
           WHERE `active` = '1'
This line    --------->        AND $sql_group_id 
           AND (`published_when` = '0' OR `published_when` <= '$server_time')
           AND (`published_until` = '0' OR `published_until` >= '$server_time')
           AND $sql_not_older_than
           ORDER BY $sql_order_by $sql_sort_order
           LIMIT 0, $max_news_items";



from sql query :)


---  ooooups, I for get to mention that its in include.php file :)
cheers
Web developer

Xagone

can we specify : THAT news feed

like, i'v got a page that dont need no "groups" but got 2 news, can i specify check that feed ?
Xagone Inc. (formerly VotreEspace)
[url="http://xagone.com/"]http://xagone.com/[/url]


doc

Hi,

latest version now also available at the Add-ons repository, thanks WebBird.

Doc

WebBird

I just released v1.11.

+ fix: break at word boundaries instead of fixed $max_news_length
+ added French language (FR.php) contributed by forum member Guillaume (ak creatile)

Download at AMASP: http://www.websitebakers.com/pages/code-snippets/listings/anynews.php?lang=EN

erpe0812

Hi WebBird

passt  :-D

Danke für die schnelle Hilfe.

Gruss

erpe

WebBird

Maybe someone wants to try this hack:

include.php, Line 217:


// leave original line, but comment out
// $row['content_short'] = substr($row['content_short'], $start_pos, $max_news_length) . '...';
// after, add:
        $row['content_short']
              = wordwrap2(
                    substr( $row['content_short'], $start_pos ),
                    $max_news_length
                ) . '...';


At end of file, BEFORE ?>, add:


function wordwrap2( $str, $width = 75, $break = '\n', $cut = true ) {
  $str = html_entity_decode( $str ); //first decode
  $out = wordwrap( $str, $width, $break, $cut ); //now wordwrap
  $out = htmlentities( $out ); //re-encode the entities
  $out = str_replace( htmlentities( $break ), $break, $out ); //put back the break
  // return the first line
  $temp = explode( $break, $out );
  return $temp[0];
}


Now, when using the cut-param...

Example:

DisplayNewsItems( 0, 10, 50 );


...the short text should be cut after 50 chars, but without breaking the last word. (So, the resulting length will be shorter than 50 in most cases.)