WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.

Donate with PayPal buttonSpenden mit dem PayPal-Button

  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Code Snippet: Display news items, anywhere
  • Print
Pages: 1 [2] 3 4 ... 21   Go Down

Author Topic: Code Snippet: Display news items, anywhere  (Read 373877 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

  • Guest
generated link paths wrong
« Reply #26 on: May 23, 2005, 07: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

fienieg

  • Guest
Code Snippet: Display news items, anywhere
« Reply #27 on: May 23, 2005, 01:37:07 PM »
Just replace this
Code: [Select]
<a href="<?php echo WB_URL; ?><?php echo $link ?><?php echo PAGE_EXTENSION; ?>"><?php echo $title; ?></a>

With:
Code: [Select]

<a href="<?php echo WB_URL; ?>/pages/<?php echo $link ?><?php echo PAGE_EXTENSION; ?>"><?php echo $title; ?></a>
Logged

jonathanbb

  • Guest
Re: Code Snippet: Display news items, anywhere
« Reply #28 on: October 13, 2005, 02:51:48 PM »
Hi

I am trying to use this snippet in my template I get a Parse Error for this line

if &#40;!$result = mysql_query&#40;$query&#41;&#41; &#123;

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, 03:05:22 PM »
if &#40;!$result = mysql_query&#40;$query&#41;&#41; &#123;


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

Offline babsy

  • Posts: 337
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&#40;id&#41; 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: [Select]
$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

Offline babsy

  • Posts: 337
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

Offline babsy

  • Posts: 337
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

Offline babsy

  • Posts: 337
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 :-D


echo '<p><a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a></p>';
Logged

ictcafe

  • Guest
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: [Select]
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

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

Offline babsy

  • Posts: 337
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: [Select]
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: [Select]
$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

  • Guest
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: [Select]
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

Offline babsy

  • Posts: 337
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

  • Guest
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: [Select]
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

Offline babsy

  • Posts: 337
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

Offline babsy

  • Posts: 337
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: [Select]
<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: [Select]
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: [Select]
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

  • Print
Pages: 1 [2] 3 4 ... 21   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Code Snippet: Display news items, anywhere
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2