Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
February 12, 2012, 01:56:28 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
149620
Posts in
21098
Topics by
7537
Members
Latest Member:
lotte2
WebsiteBaker Community Forum
English
Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
(Moderator:
Argos
)
Code Snippet: Display news items, anywhere
Pages:
1
[
2
]
3
4
...
21
Go Down
Author
Topic: Code Snippet: Display news items, anywhere (Read 100190 times)
fienieg
Guest
Code Snippet: Display news items, anywhere
«
Reply #25 on:
March 26, 2005, 01:46:16 PM »
Quote from: Argos
What do you mean by that?
I tried this code snippet, and it works allright.
In the code page they don't allow <? and ?>, so if you want to use it, you need to use the echo command, in stead of using a php break, and then adding html!
Logged
valerie
Offline
Posts: 156
generated link paths wrong
«
Reply #26 on:
May 23, 2005, 06:10:56 AM »
Hi. I'm trying to learn about using code snippets. Maybe you can help me with this: I inserted the code into the template and it worked, but the links it generates are missing the pages folder:
I get:
http://www.sweetike.com/wbaker/wb/posts/albuquerque-here-we-come2.php
Not:
http://www.sweetike.com/wbaker/wb/pages/posts/albuquerque-here-we-come2.php
Can you tell me what to insert into the code to correct this?
Thanks!
Logged
http://www.robcomm.net
--editing and proofreading for American English
--print and web publication management
--graphic and web design, including original photography
fienieg
Guest
Code Snippet: Display news items, anywhere
«
Reply #27 on:
May 23, 2005, 12:37:07 PM »
Just replace this
Code:
<a href="
<?php
echo
WB_URL
;
?>
<?php
echo
$link ?>
<?php
echo
PAGE_EXTENSION
;
?>
">
<?php
echo
$title
;
?>
</a>
With:
Code:
<a href="
<?php
echo
WB_URL
;
?>
/pages/
<?php
echo
$link ?>
<?php
echo
PAGE_EXTENSION
;
?>
">
<?php
echo
$title
;
?>
</a>
Logged
jonathanbb
Offline
Posts: 21
Re: Code Snippet: Display news items, anywhere
«
Reply #28 on:
October 13, 2005, 01:51:48 PM »
Hi
I am trying to use this snippet in my template I get a Parse Error for this line
if (!$result = mysql_query($query)) {
and have no clue why.
To be truth full I dont have a clue what that line does either so hope someone out there can help me.
Thanks
Jonathan
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #29 on:
October 13, 2005, 02:05:22 PM »
if (!$result = mysql_query($query)) {
There are display codes in them, it is an old post, some leftovers from the forum migration.
Try the other one, posted by Craig.Rodway that one will work.
Happy Baking!
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #30 on:
November 18, 2005, 10:07:51 AM »
Hi all!
Now i tryed, to use, it, and i can get it to work, in the template (exept, when i press the link, it says, "the page can not be found"....
Then i tryed to use it on a page, as i want - but there i only get this message on the page
(title; $id = $data->post_id; $link = $data->link; echo '
'.$title.'
';}#125; ?> )
that what i can see on the page i put the code in....
this is the code i used:
<!-- NEWS READER -->
<?php
$group = 0; // 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 posted_when DESC
LIMIT 0, 5;"; // 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 '<p><a href="'.WB_URL.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';}#125;
?>
<!-- END NEWS READER -->
how do i set the code correct onto a page?..... please help, someone
«
Last Edit: November 23, 2005, 03:28:57 PM by babsy
»
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #31 on:
November 23, 2005, 08:35:46 PM »
This is the code you need: you can place it in your template or you can place it in a code section
Code:
$group = 2; // 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, 5;";
/*
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 '<p><a href="'.WB_URL.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
}
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #32 on:
November 24, 2005, 10:12:15 AM »
hi again,
i must be missing something, because when i put it in the code page... nothing happens, the page is just empty??
is there a special way to put it in the code?
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #33 on:
November 24, 2005, 02:24:52 PM »
did you check the group?
?
Make sure the group is the same you have, or it won't show anything
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #34 on:
November 24, 2005, 02:38:40 PM »
hi agin.... thanks.... i set group to "0".... and it worked fine..... thank you......
now i just have to make it look like i want... thank you again.... if i want to change it, i should change in this same code, right?
i want it to show the "short" text under the title also.....
well... just 1. problem... it doesn´t find the pages.. it looks for a folder called post, put it inside the pages folder, but i don´t know where to set the /pages/ in the code?
«
Last Edit: November 24, 2005, 02:58:04 PM by babsy
»
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #35 on:
November 24, 2005, 03:34:15 PM »
change: echo '<p><a href="'.WB_URL.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
to : echo '<p><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
or :echo '<p><a href="'.WB_URL.'pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
don't have time to test
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #36 on:
November 24, 2005, 03:41:03 PM »
Hi again.. and thanks...
this is the one that worked, thanks
echo '<p><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
Logged
ictcafe
Offline
Posts: 7
Re: Code Snippet: Display news items, anywhere
«
Reply #37 on:
November 26, 2005, 03:31:29 PM »
I've tweaked a little the code, but two questions:
1. how get i the short description under the title
2. how do i get an unsorted list from all the items?
Code:
global $database;
$query = "SELECT post_id,title,group_id,page_id,link,short FROM ".TABLE_PREFIX."mod_news_posts WHERE page_id = $page_id ORDER BY post_id DESC LIMIT 0, 5;";
/*
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;
}
echo "Last 5 news posts:"."<br>";
while($data = mysql_fetch_object($result)){
$title = $data->title;
$page = $data->page_id;
$id = $data->post_id;
$link = $data->link;
$short = $data->short;
echo '* <a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></br>';
}
Logged
Harry Dubois
webmaster HET ICT-Cafe
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #38 on:
November 26, 2005, 06:12:41 PM »
Fetch the stuff you need from the database
You need content_short (look at table mod_news_post) for all the fields
The <ul><li> ... </li></ul>, just add it to the output:
Something like this:
Code:
global $database;
$query = "SELECT post_id,title,group_id,content_short, page_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE page_id = $page_id ORDER BY post_id DESC LIMIT 0, 5;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
print "$error";
exit;
}
echo "Last 5 news posts:"."<br>";
echo "<ul>"; // start of the loop
while($data = mysql_fetch_object($result)){
$title = $data->title;
$page = $data->page_id;
$id = $data->post_id;
$link = $data->link;
$short = $data->short_content;
echo '<li><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a>'.$short.'</li>'; // the loop
}
echo "</ul>"; // end of the loop
Didn't test it!
John
«
Last Edit: November 26, 2005, 06:14:57 PM by pcwacht
»
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #39 on:
November 28, 2005, 01:01:26 PM »
hi all!
i tryed to change the code a bit, and so far, so good!
BUT... i want it to show the pictures that are shown along the "short text too", but i cant fint the id, in the database, does anyone know where the pictures goes in the database.
This i my code for now:
$group = 0; // Specify the Group(id) you want to read the news from
global $database;
$query = "SELECT post_id,title,short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = $group ORDER BY position DESC LIMIT 0, 10;";
/*
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;
$short= $data->short;
$id = $data->post_id;
$link = $data->link;
echo '<br />';
echo '<table width=100%>';
echo '<tr><td bgcolor=#e7e7e7><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></td></tr>';
echo '<tr><td>'.$short.'</td></tr>';
echo '</table>';
}
Plesase any help wanted?
i know where to put it in the code,just can´t find it in the mysql database???
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #40 on:
November 28, 2005, 01:46:39 PM »
Doesn't seem to be in the database.
module/news/view.php reveals:
Code:
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
} else {
$groups[$group_id]['image'] = '';
}
So something like this might work (mind you , I had no time to test it!!)
Code:
$group = 0; // Specify the Group(id) you want to read the news from
global $database;
$query = "SELECT post_id,title,short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = $group ORDER BY position DESC LIMIT 0, 10;";
/*
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;
$short= $data->short;
$id = $data->post_id;
$link = $data->link;
$group_id = $data->group_id;
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
$picture = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
} else {
$picture = '';
}
echo '<br />';
echo '<table width=100%>';
echo '<tr><td colspan=2 bgcolor=#e7e7e7><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></td></tr>';
echo '<tr><td>'.$picture.'</td><td>'.$short.'</td></tr>';
echo '</table>';
}
You could change the $picture = ''; to a NoImage picture with:
$picture = WB_URL.MEDIA_DIRECT
ORY.'/.news/noimage.jpg';
Happy baking,
John
Logged
restonian
Offline
Posts: 11
Re: Code Snippet: Display news items, anywhere
«
Reply #41 on:
November 28, 2005, 07:34:40 PM »
I noticed that a few posts back there was a post including code that didn't have a group id defined inside it, i tried this myself, and it displayed nothing. Not a sausage.
Is it possible to have the latest news stories globally over every category?
If so what do i alter?
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #42 on:
November 28, 2005, 11:29:20 PM »
Yes it is possible, rather easy,
take out the test on $group in the query
or take a look at this one:
http://forum.websitebaker.org/index.php/topic,1851.msg11398.html#msg11398
or try this one:
Code:
global $database;
$query = "SELECT post_id,title,group_id,link FROM ".TABLE_PREFIX."mod_news_posts ORDER BY position DESC LIMIT 0, 5;";
$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 '<p><a href="'.WB_URL.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
}
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #43 on:
November 29, 2005, 12:40:54 PM »
Hi i haven´t got the image working yet, but i´m still trying to work on that!
for now i have used the snippet, with group=0
but now a have on page (sport) with four subpages (football, hockey, tennis, else)
How can i make the snippet work so it just shows these four subpages... how can i find what group they are, i can just find page_id, and thats different for every page???
Logged
restonian
Offline
Posts: 11
Re: Code Snippet: Display news items, anywhere
«
Reply #44 on:
November 29, 2005, 07:12:48 PM »
Magic!
Cheers John.
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #45 on:
November 29, 2005, 07:40:44 PM »
@babsy,
This snippet only will show news posts
So if your posts are divided among those four pages testing for the pageid is the obvious thing to do.
Code:
global $database;
$get_page = 1; // change to your page_id you need
$query = "SELECT post_id, title,group_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE page_id=$get_page ORDER BY position DESC LIMIT 0, 5;";
$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 '<p><a href="'.WB_URL.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
}
The fields you can choose from are:
post_id, section_id, page_id, group_id, active, position,
title, link, content_short, content_long, commenting, posted_when, posted_by
phpmyadmin shows you that in a jiffy
Happy baking,
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #46 on:
December 06, 2005, 02:06:24 PM »
Hi everyone, i´m still trying to get this picture to work... but i just can´t find the picture folder anywhere - does any off you know the path to the pictures in "short text" in the news, my code for now looks like this:
$group = 0; // Specify the Group(id) you want to read the news from
global $database;
$query = "SELECT post_id,title,short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = $group ORDER BY position DESC LIMIT 0, 10;";
/*
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;
$short= $data->short;
$id = $data->post_id;
$link = $data->link;
$group_id = $data->group_id;
if(file_exists(WB_PATH.MEDIA_DIREC
TORY.'/.news/image'.$group_id.'.jpg')) {
$picture = WB_URL.MEDIA_DIRECT
ORY.'/.news/noimage.jpg';
} else {
$picture = '';
}
echo '<br />';
echo '<table width=100%>';
echo '<tr><td bgcolor=#e7e7e7><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></td></tr>';
echo '<tr><td>'.$picture.'</td><td>'.$short.'</td></tr>';
echo '</table>';
}
But it just leaves an empty hole.... try take a look at this!
http://www.kjolurin.com
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #47 on:
December 06, 2005, 03:51:40 PM »
I see pictures on that page, looks like a bowling ally?
John
Logged
babsy
Offline
Posts: 311
Re: Code Snippet: Display news items, anywhere
«
Reply #48 on:
December 06, 2005, 03:58:10 PM »
hi, and sorry
i forgot, i had set, the page to "hidden" now you should see it right!
www.kjolurin.com
Logged
pcwacht
Guest
Re: Code Snippet: Display news items, anywhere
«
Reply #49 on:
December 06, 2005, 04:42:58 PM »
Did you look at your source of that page?
Code:
<a href="http://www.kjolurin.com/pages//posts/rrrrrrrrrrrrrrrrrrrr146.php">rrrrrrrrrrrrrrrrrrrr</a></td></tr><tr><td></td><td><p><img height=\"73\" hspace=\"5\" src=\"/media/Image/bowla.jpg\" width=\"142\" align=\"left\" border=\"1\" /><img height=\"1\" src=\"/\"//\"/media/Image/bowla.jpg//\"/\"\" width=\"1\" border=\"0\" /><br /><img style=\"\"WIDTH: \" height=\"1\" src=\"/\"/media/Image/bowla.jpg/\"\" width=\"1\" border=\"0\" />
Doesn't look all to good to me
The images should come from the /media/.news directory! Not from /media/Image ....
I searched the source of your page for /media/.news nothing found!
In your posted code, this bit:
Code:
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
$picture = WB_URL.MEDIA_DIRECTORY.'/.news/noimage.jpg';
} else {
$picture = '';
}
If the picture exists, set picture to noimage.jpg or to nothing?
Maybe change to following:
Code:
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
$picture = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
} else {
$picture = '';
}
So if the picture exists it will get the url to the picture.
PS, The pictures for groups needs to be upoloaded first!
admin -> pages -> the page with news -> add groups (or modify group)-> image!!!!!!!!!
John
Logged
Pages:
1
[
2
]
3
4
...
21
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
-----------------------------
English
-----------------------------
=> Help & Support
-----------------------------
General
-----------------------------
=> WebsiteBaker Website Showcase
-----------------------------
English
-----------------------------
=> Modules
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
-----------------------------
General
-----------------------------
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
-----------------------------
General
-----------------------------
=> Security Announcements
-----------------------------
Deutsch (German)
-----------------------------
=> Hilfe/Support
-----------------------------
General
-----------------------------
=> Documentation
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
=> Module & Snippets
-----------------------------
English
-----------------------------
=> Archive (posts up to 2007)
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Deutsch (German)
-----------------------------
=> jQuery
=> Tutorials
=> Templates & Design
-----------------------------
English
-----------------------------
=> jQuery
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
===> Suggestions
-----------------------------
Deutsch (German)
-----------------------------
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
===> Vorschläge
-----------------------------
English
-----------------------------
===> Software bugs
-----------------------------
Deutsch (German)
-----------------------------
===> Softwarefehler
=====> Module / Extensions
-----------------------------
English
-----------------------------
=====> Modules / Extensions
-----------------------------
Deutsch (German)
-----------------------------
===> Erfahrungs und Testberichte
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...