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

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #325 on: July 17, 2009, 01:05:55 PM »
Thanks, doc, for the hints. I will take care of it.

I just added a wordwrap2() function that hopefully will fix the text cut issue. :-D

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #326 on: July 17, 2009, 01:07:31 PM »
P.S.: Webbird nice to see that you will maintain the snippet in the future :-)

Well, it's easy to take care of a module I use myself. :wink: Thank you for this great snippet!

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #327 on: July 17, 2009, 01:17:08 PM »
Maybe someone wants to try this hack:

include.php, Line 217:

Code: [Select]
// 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:

Code: [Select]
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:
Code: [Select]
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.)

erpe0812

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #328 on: July 17, 2009, 01:43:03 PM »
Hi WebBird

passt  :-D

Danke für die schnelle Hilfe.

Gruss

erpe

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #329 on: August 13, 2009, 03:27:50 PM »
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

doc

  • Guest
Anynews
« Reply #330 on: August 13, 2009, 04:53:42 PM »
Hi,

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

Doc

WebBird

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #331 on: August 14, 2009, 10:42:14 AM »
Thank you, doc. :-D

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Re: Code Snippet: Display news items, anywhere
« Reply #332 on: August 21, 2009, 09:58:08 PM »
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)
http://xagone.com/

Offline crnogorac081

  • Posts: 1995
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #333 on: August 21, 2009, 11:03:32 PM »
You can remove:

Code: [Select]
       $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
UI / UX Designer

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Re: Code Snippet: Display news items, anywhere
« Reply #334 on: August 24, 2009, 04:56:18 PM »
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)
http://xagone.com/

Offline crnogorac081

  • Posts: 1995
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #335 on: August 24, 2009, 05:22:27 PM »
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 ?
UI / UX Designer

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Code Snippet: Display news items, anywhere
« Reply #336 on: August 24, 2009, 05:36:19 PM »
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

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Re: Code Snippet: Display news items, anywhere
« Reply #337 on: August 24, 2009, 05:39:46 PM »
done it.

i've modified include.php of version 1.11 to make the function do this :
Code: [Select]
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 :
Code: [Select]
sanitizeUserInputs($section_id, 'i{0;0;999}');just after the line with this
Code: [Select]
sanitizeUserInputs($group_id, 'i{0;0;999}');
i've added this :
Code: [Select]
// 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 :
Code: [Select]
// 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 :
Code: [Select]
$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)
http://xagone.com/

Offline crnogorac081

  • Posts: 1995
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #338 on: August 24, 2009, 05:41:47 PM »
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
UI / UX Designer

Offline Luckyluke

  • Posts: 556
  • Gender: Male
  • Let's Rock
Re: Code Snippet: Display news items, anywhere
« Reply #339 on: August 25, 2009, 04:39:20 PM »
Hi,

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

Code: [Select]
<?php
if (function_exists(&#39;displayNewsItems&#39;))  {
  
if (LANGUAGE == &#39;NL&#39;)  {
    
displayNewsItems(2,3,-1,1,&#39;nl&#39;,true, &#39;<p><a><img>&#39;,&#39;none&#39;,4, 3,&#39;disabled&#39;);
  
} else {
        
displayNewsItems(3,3,-1,1,&#39;en&#39;,true, &#39;<p><a><img>&#39;,&#39;none&#39;,4, 3,&#39;disabled&#39;); 
  
}

?>

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

Offline Xagone

  • Posts: 482
  • Gender: Male
  • Developper
    • Xagone Inc
Re: Code Snippet: Display news items, anywhere
« Reply #340 on: August 25, 2009, 04:45:34 PM »
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)
http://xagone.com/

erpe0812

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #341 on: August 25, 2009, 05:11:09 PM »
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

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #342 on: August 25, 2009, 07:15:19 PM »
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

Offline Luckyluke

  • Posts: 556
  • Gender: Male
  • Let's Rock
Re: Code Snippet: Display news items, anywhere
« Reply #343 on: August 25, 2009, 10:22:36 PM »
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

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Code Snippet: Display news items, anywhere
« Reply #344 on: August 26, 2009, 07:24:41 AM »
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

Offline Luckyluke

  • Posts: 556
  • Gender: Male
  • Let's Rock
Re: Code Snippet: Display news items, anywhere
« Reply #345 on: August 28, 2009, 12:41:00 PM »
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

Offline bikerider

  • Posts: 21
Question from the very beginning
« Reply #346 on: September 02, 2009, 07:11:13 AM »
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
Code: [Select]
<?php 
        
if(function_exists(&#39;display_news_items&#39;)) {
          
display_news_items(05501"""mehr lesen""aktuell gibt es keine news..."false);
        } else {
          echo &
#39;Requires code snippet anynews (WB addons repository) to display news here.&#39;;
        
}
      
?>
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

doc

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #347 on: September 02, 2009, 07:39:36 AM »
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

Offline bikerider

  • Posts: 21
Re: Code Snippet: Display news items, anywhere
« Reply #348 on: September 02, 2009, 08:35:59 AM »
that's it - didn't remark that...  :oops:

thank you very much!!

Offline bikerider

  • Posts: 21
Re: Code Snippet: Display news items, anywhere
« Reply #349 on: September 02, 2009, 09:38:57 AM »
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:
Code: [Select]
<!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(&#39;DEFAULT_CHARSET&#39;)) { echo DEFAULT_CHARSET; } else { echo &#39;utf-8&#39;; }?>" />
<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, &#39;<li [if(class==menu-current){id="menu-current"}]>[a]<span>[menu_title]</span></a>&#39;); ?>
    <?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, &#39;<dt>[a][menu_title]</a>&#39;, &#39;</dt>&#39;, &#39;<dl class="nav3-grid">&#39; , &#39;</dl>&#39;);?>
     
    </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(&#39;displayNewsItems&#39;)) {
          
display_news_items(05501"""mehr lesen""aktuell gibt es keine news..."false);
        } else {
          echo &
#39;Requires code snippet anynews (WB addons repository) to display news here.&#39;;
        
}
      
?>

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

 :?

 

postern-length