Code Snippet: Display news items, anywhere

valerie

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!

fienieg

Quote from: ArgosWhat 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!

Argos

Quote from: fieniegthanks craig, but some level of understanding of WB is needed with the code snippets...  :wink:  (dont make to easie for them  :P  :twisted:  :roll: )

What do you mean by that?  :?  I tried this code snippet, and it works allright.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fienieg

thanks craig, but some level of understanding of WB is needed with the code snippets...  :wink:  (dont make to easie for them  :P  :twisted:  :roll: )

Craig.Rodway

Just a little update to the snippet...

If you want to put it into a Code section - you can, use this code below:

$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>';
}


It simply removes the <?php and ?> tags, and echos the link properly :)

fienieg

i also got one or two of those javascripts...
i'm fine tunning them...

Stefan

It's just that I don't have time to play around with it. Something is always the problem - either its compatibility or looks or whatever.
I was hoping you had found a good one that could be used. I would have just written the php part, which should be no big deal.

Argos

Ah! I didn't realize you were looking for a free script to include in WSB :-)

There are free dhtml menu available though, but I haven't tried them.
I've got http://www.dynamicdrive.com/ in my bookmarks. They have some I know. And Google knows some as well :-) http://www.google.nl/search?hl=nl&q=free+dhtml+menu&lr=
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Stefan

Well, it's not a solution for a standard WB dynamical menu if it's not free, but still, thanks for the tip.

Argos

Quote from: StefanYeah, too bad really.
I've had a look at your javascript code - quite confusing with all the numbers, spacers and what not.
To make an automatically maintained menu, it is necessary to have a way of writing the entries without any individual hacks. So say, I give you a menu structure:
Top1
---T1Sub1
---T1Sub2
Top2
---T2Sub1
---T2Sub2
can you (manually) make a nice-looking dhtml menu out of that without any further information, hacks, etc. No tweaking allowed!
If so, it's no problem to make the transition to a true WB dynamical menu. I've just not looked into dhtml menus at all, otherwise I would've done it already.

Yeah, I know the code looks terribly complicated, but it is generated by the program I use: http://www.sothink.com/webtools/dhtmlmenu/index.htm

Actually, it has the built-in option of creating menu's dynamically with PHP or other methods, but I am not a programmer so I don't really understand how I should do that :cry:  

I like this software very much, I use it a lot. It's powerful and very user friendly, using a drop and drag, WYSIWYG way of creating menus. Rather cheap too: only 35 dollars. Maybe you could check it out...
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Stefan

Yeah, too bad really.
I've had a look at your javascript code - quite confusing with all the numbers, spacers and what not.
To make an automatically maintained menu, it is necessary to have a way of writing the entries without any individual hacks. So say, I give you a menu structure:
Top1
---T1Sub1
---T1Sub2
Top2
---T2Sub1
---T2Sub2
can you (manually) make a nice-looking dhtml menu out of that without any further information, hacks, etc. No tweaking allowed!
If so, it's no problem to make the transition to a true WB dynamical menu. I've just not looked into dhtml menus at all, otherwise I would've done it already.

Argos

Quote from: Stefan
Quote from: Argos
You can see it on http://www.bereikbaarheid.nl/cms

Do I see it correctly that you have written a Javascript menu that uses the WebsiteBaker page tree? If so, would you be willing to release it to the general public?

I wish I could do that :-)
No, it's just a seperate DHTML menu I included in the template. All links must be made manually. In this case that is okey, because the client doesn't need to create pages or change the structure of the site. Only modify existing pages. And if he needs to have other pages, he can create them, but I have to add them to the menu...

Too bad it isn't a dynamically created menu, ain't it? :-)
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Stefan

Quote from: Argos
You can see it on http://www.bereikbaarheid.nl/cms

Do I see it correctly that you have written a Javascript menu that uses the WebsiteBaker page tree? If so, would you be willing to release it to the general public?

Argos

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fienieg

yeah i only  :lol:  publish templates freely... and i leave name in the credits.
I'll just mention you in the credits section

these templates
http://www.templateserver.com/index.php?action=detail&cat_id=17&image_id=108
http://www.templateserver.com/index.php?action=detail&cat_id=17&image_id=81
http://www.templateserver.com/index.php?action=detail&cat_id=17&image_id=80

these 3 a could make into templates, for general use...

Argos

#12
Well, I will create them myself because they are not generally usable yet. They refer to clients, aren't really finished yet, or dont have the proper quality.

But you can also take a look at [url removed becasue no longer in use] where I sell templates memberships. If you can pick a few (no, not all!) that you feel may be usable as a basis for WSB templates, please let me know and I'll send them to you. But only for use as WSB templates that will be published freely! And I want my name/website mentioned in the html source.

By the way, I did not create these templates myself. Half of them were created by someone for me exclusively, and the other half were made by someone who I have made a template swapping deal with.
Only this one I created myself: [url removed becasue no longer in use] which I will transform into a WSB templaet myself.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fienieg

your welcome...

we all contribute to WB, you may send me your works, and maybe i can turn them into some templates  :wink:

Argos

Fienieg, you made my day by saying nice things (thanks!) and solving my little problem. Great, I appreciate it!!

Most of the times I can tweak scripts here and there, but I don't really understand why it works or not. Creating something myself is out of my league. What I do is based on limited insight, and much trial and error. I don't have real knowledge and skills, which is annoying. I really should learn at least the basics of PHP... If only I had the time :-(

I will create some templates in the near future to give something back to the community. I have some designs from projects that didn't make it to the end, and some tryouts for myself. I can customize them into WSB templates.

By the way, your News script is in fact very useful, and I use it not only for posting news and events, but also as a FAQ. The FAQ Baker module is not very useful I think, because it's just a long list of entries. That's only useful if you have only a few questions. Your News module is perfectly usable for a FAQ that can grow larger over time. If you keep updating it, it will be a very powerful module indeed!
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fienieg

Quote from: ArgosHm... I'm still happy, but I noticed a small problem. The listing in the snippet is chronological, in order of input. When I change the order of the items in the backend, the order on the news page changes too, so that is correct. But the order of the snippet listing isn't affected by the back end change. Can this be changed? I know the snippet listing is a light version of the normal news listing, but I would like it to be just bit heavier, so that it listens to changes in the back end...

You can see it on http://www.bereikbaarheid.nl/cms.
This is a site I am working on for a client. It is not operational yet, and a number of things are not finished yet. But the news listing is working. It's a Dutch site, but that shouldn't be problem to see what mean.

Damn that template is looking nice... it's a beauty...
(and i'm dutch so i can read it ;))

I made the news script, so all news items added to the database, and only the latest 5 are displayed... you can also make it, replacing, ORDER BY posted_when by ORDER BY position, then it's affected by the admin back end.

But this is just a little snippet i'll try to build one with more options...

Argos

Hm... I'm still happy, but I noticed a small problem. The listing in the snippet is chronological, in order of input. When I change the order of the items in the backend, the order on the news page changes too, so that is correct. But the order of the snippet listing isn't affected by the back end change. Can this be changed? I know the snippet listing is a light version of the normal news listing, but I would like it to be just bit heavier, so that it listens to changes in the back end...

You can see it on http://www.bereikbaarheid.nl/cms.
This is a site I am working on for a client. It is not operational yet, and a number of things are not finished yet. But the news listing is working. It's a Dutch site, but that shouldn't be problem to see what mean.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Argos

Very cool!! I tried it, and it works like a charm. I am very happy!!!  :D  :D
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Argos

OK, thanks. So snippets are template based, not page based? Is it possible to convert a snippet to a module? That way you can add it to pages without having to create another template for it, if you don't want to have it on every page.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

fienieg


fienieg

just place the snippet into your template... any where you want to display the latest news items...

Argos

I would LOVE to use this snippet, but I don't know how :-(

When I copy the code into a Code module, it doesn't work. So I guess that is not the way it should be used... What is the right way to use this snippet?

And how do I have to use the Code module anyway? Can you just paste any HTML, JS, or PHP into it? I guess not, but I don't know how to use it properly...
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!