Code Snippet: Display news items, anywhere

spida

Hello,

I hope I don't sound presumptuous, and I admit in advance that I haven't read this thread completely in detail. But I have taken kweitzel's code from the metal-slabs template and changed it a little to my needs.

You can find the changed code as well as a short description of what I did at my wiki: http://www.rot65.de/dokuwiki/doku.php/cms/WebsiteBaker/debug

Kind regards,
Ayshe

kweitzel

did you define groups in the newmodule? If yes, you can find the group ID by editing the group. Then it is shown in the URL of the page.

cheers

Klaus

sHsIkuA

Hello need some help here

The snippet only work when I put the group id to 0 , other than that its not working at all

Where can I get my group_id ?


kida

Hey

That's great - nice solution

Cheers

Darren

doc

#98
Hello,

this is not supported, but you can implement that function by your own.

You need to modify the include.php of the anynews snippet. The output is generated between lines 92 and 121. The following code would extract the date from the database and convert it into human readable format (English style). Only place it within the while loop (lines 92-121).

echo date("m/d/Y", $data[posted_when]);

To style the output format of the date, have a look to the PHP function code (google)  :-)

Regards Christian

kida

Hey - works well,

I need it for like an online daily diary..

Anyway to include the date the item was posted with anynews?

Cheers

Darren

doc

Hello,

set the visibility of HR to none or set the color of HR to your background color or remove the HR from the code in include.php.

Regards Christian

4bizmedia

Hi, just wondering if there was an easy way to eliminate the <hr> that is displayed at the end of each snippet, instead having just a blank space.  CSS can make the <hr> small, but can't eliminate it completely.

doc

Hello,

the code below assumes that you have sticked to the tutorial for multi language pages. Languages specific pages must be stored in directories like:
DE: ../wb/de/home.php
EN: ../wb/en/home.php

Add the following code (without start <?php and ending ?> tags) into a page of the type code.


<?php
// getting the calling page URL (../webserver/en/home.php)
$current_page $_SERVER['PHP_SELF'];

// using regular expression to extract the language part from the URL (/en/, /ge/, /it/...)
$language_used "";
if(
preg_match('#/(..)/#i'$current_page$language)) {
  
$language_used $language[1];
}

// define text output depending on choosen language
switch ($language_used) {
  case 
"DE":  // german language
     
$news_header "Letzte Nachrichten";
     
$news_more "mehr...";
     
$news_no "keine Nachrichten vorhanden...";
     break;
  
  case 
"EN"// english language
    
$news_header "Latest News";
    
$news_more "read more";
    
$news_no "no news available yet...";
    break;
  
  default:  
// if LANGUAGE could not be detected
    
$news_header "Your heading text";
    
$news_more "Your more text";
    
$news_no "your no new text";
    break;
}   

// call the anynews snippet
display_news_items(010, -11$news_header$news_more$news_notrue);
?>



If someone knows a better way of extracting the page language, please post it here.

Regards Christian

ruebenwurzel

Hello,

a few days ago a read a post where a user solved this with adding the language variable to the requests. Cannot find the thread, but maybe you have mor luck when you search yourself  :wink:

Matthias

propelled

Hello.

Module anynews works perfect. I dont have experience with php and I need two things to get work this module correctly. Both thing with multilingual site.

First is: I want show texts Lastest News and Read More at language file, to make finnish or russian page fully finnish or russian. I tried replace it with [READ_MORE] but it dont work.

Second is: I have made multilingual site with tree what was explained on multilingual site wiki. It is right now this:
fin
- page1
- page2
- news (news on finnish language)
eng
- page1
- page2
- news (news on english)
rus
- page1
- page2
- news (news on russian)

How to make possible show with anynews module on russian page news on russian language and etc (same with other languges)?

doc

@Olli:
I dont think that this is related to the anynews snippet, but to the news module itself.

Regards Christian

Olli

hello everyone,
i tried the snipped a while back and i love it :-)

but there is one thing, that's not working properly. let's say you've got a WB-link inside the short-text area.

this WB-link does not get "translated" to the real URL.
it says "www.mydomain.com/pages/[wblink2]" or something like this.

is this fixed already?

thanks guys

doc

@G4
You could try the following workaround:
Put all news items of Newspage 1 into a group (e.g. news1), all news items of Newspage 2 into another group (e.g. news2). Assuming that group news1 has the number 5, news2 the number 6, try the following code:


display_news_items(5, 1, -1, 1, "Latest News", "read more", "no news available yet...", true);
display_news_items(6, 1, -1, 1, "Latest News", "read more", "no news available yet...", true);


Regards Christian

kweitzel

you can only (with the default setup) generate the different groups. Otherwise you will need to change the script, so it checkes the page_id as reference for the postings ...

cheers

Klaus

G4

Is it possible to show 2 newsitems on the frontpage from 2 different news pages. In the module i can not find a page ID. Or is there some other way to do this.

NEWSPAGE 1
item A
item B
item C

NEWSPAGE 2
item X
item Y
item Z


On the frontpage I want to show
LATEST
item A
and
item X

hr_d

Hello Christian,

I tested it, very good job!

Thank you. http://www.frettchen.raith.ws/

Regards Hermann

doc

Have added the option to suppress striping off tags from news title, and short news text. In addition I removed all inline CSS styles, as they can´b be overwritten via external CSS definitions.

Added a README file to the zip file in the addons repository which explains all possible functions.

Regards Christian

hr_d

Hello Christian,

that worked fine. Thank you! http://www.frettchen.raith.ws/

Perhaps you can make a parameter in the next version.

Regards Hermann

doc

Hello Hermann,

not possible with the latest version, as I am using the PHP command strip_tags() to remove all HTML tags from the short text. So in your case, image tags like <img> will be striped from the short news text.

Try to remark the strip_tags command for short news text in line 83 in anynews/include.php
//$data['content_short'] = strip_tags($data['content_short']);

Regards Christian

hr_d

Hello,

works very well.

I have small pictures in the short text news!. It is possible to show these also?

Have a look: http://www.frettchen.raith.ws/pages/news.php

Thank you!
Hermann

Hans

Hans - Nijmegen - The Netherlands

doc

Hello Hans,

you need to pass over text in " " or ' ' like shown below:
display_news_items(0, 10, -1, 1, "Test test", "test tesset", " no test");
display_news_items(0, 10, -1, 1, 'Test test', 'test tesset', ' no test');

Have tested this and it works. If you forget the " ", the number of arguments will not fit the expected number.

Regards Christian

Hans

#79
Hi Doc
thanks!
One problem though: when adding a space in $header_text or $readmore_txt I get this message:
Parse error: syntax error, unexpected T_STRING in /home/dernjen/public_html/modules/code/view.php(30) : eval()'d code on line 1

(I replaced $header_text and $readmore_txt with normal text (Dutch: Lees meer = English: Read more), maybe I have it the wrong way? When I replace it with one word or two with an underscore I get no errormessage (although the underscore is visible in the link).
Hans


Hans - Nijmegen - The Netherlands

doc

#78
Hello,

please find attached the updated version of the anynews snippet module. To upgrade, just install it over the previous one.

Have added the additional parameter $display_mode which allows you to output a detailed list (news title, short text, link to news item), or a simple unsorted list (link to news item, link text = news title). In addition I added the option to display the full short text ($max_news_length=-1, which is now the default) or no short text at all ($max_news_length=0). The latest version creates now valid (X)HTML output (forgot the closing slash in the <hr /> element).


<?php display_news_items($group_id$max_news_items$max_news_length,
$display_mode$header_text$readmore_text$no_news_text); ?>



Optional parameters:
group_id...  group from which you want to read news from (default:= 0 for all groups)
max_news_items...  max number of news shown (default:= 10, no value >10 accepted)
max_news_length... max length of the short news text shown (default:=-1 for full news length)
display_mode... 1:=details (default); 2:=unsorted list
header_text...  heading text shown (default:="Latest news")
readmore_text... text displayed for readmore link (default:=read more)
no_news_text...   text shown if no news available (default:="no news avaialbe yet...")

[Edited 18.2.07, 22:38]
Example for customised call:
display_news_items(0, 5, 50, 2, "The latest news", "show full news text", "uup, no news available");

Troubleshooting:
- pass over either no argument, or all arguments in expected order
- mask text with "your text " or 'your text '
- within your template index.php file use: <?php display_news_items(); ?>
- within a code module use: display_news_items();
- remind the ; at the end of the code line

Custom formating:
The output can be customized to your needs without touching the code itself. This is realised by the use of CSS definitions. Open a code page and enter the following code:

echo "<div id=\"mynews\">";
display_news_items(0, 3, 15, 1, "Last news", "more...", "no news yet");
echo "</div>";


The additional div section is used to restrict the style defintions to the news only, without influencing the rest of your layout. The following CSS examples needs to be added to the CSS file of your template.

The font size of the news text is too big?
#mynews p {font-size:80%; }

You want the news title to show up in brown?
#mynews strong {color:brown; }

The news header should have a left brown border?
#mynews h2 {border:1px dotted brown; margin:5px; padding:0;}

Please keep in mind: I will not aks any questions on CSS formating.
A lot of pages are available for free in the internet. http://www.css4you.de/, http://glish.com/css/

Regards Christian

Removed file. Any news is now available in the section Additional Functions on addons repository