[Pro] showing several newsitems in one page

Hi all.
I have some html experience but i can;t figure this on eout by myself…
I’m making a website and it has a news section. Basically what i want is on 1 page a panel on the left that shows all the newsitems. and then a bigger panel to the right that shows the detailed information of a newsitem. So if you click newitem 2 in the left panel, it should give you detailed info about this newsitem in the rightpanel.

Is this possible with php for example or anything else? If yes, then how do i do it?

I hope somebody can help me out. Thanx in advance.

gr, Wouter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I would use a system like WebYep to get the news into your page. The loop features in that system would let you create a collection of stories as long as you like, with only one “template” version of the story actually drawn on the page in Freeway. The idea is that you put all of the stories into the page where you want the one story to appear, then take all of the stories back out using JavaScript and use that JavaScript to create the effect.

So let’s say your news is now structured like this in your rightpanel element (at least this is how the HTML that WebYep generates looks):

<div id="rightpanel" style="...">
    <h3><a href="link/to/story">Headline</a></h3>
    <p>A lovely description of the story</p>
    <h3><a href="link/to/story">Headline</a></h3>
    <p>A lovely description of the story</p>
    <h3><a href="link/to/story">Headline</a></h3>
    <p>A lovely description of the story</p>
</div>

Apply Protaculous to the page, and choose prototype-packed from the Library picker. Click on the top Function Body button, and paste in the following:

var rightpanel = $('rightpanel');
var stories = rightpanel.select('h3').each(function(elm){
    elm['link'] = elm.down('a').href;
    elm['description'] = elm.next('p').remove();
    elm.update(elm.down('a').innerHTML).setStyle('cursor:pointer');;
    elm.remove();
});

At this point, nothing is left in the rightpanel box, the headlines, links, and their descriptions have been collected by Prototype into an array-like structure called an Enumerable, and they are ready to use.

To put the headlines into your sidebar and make them clickable:

var leftpanel = $('leftpanel');
stories.each(function(story){
    leftpanel.insert(story);
    story.observe('click',function(evt){
        rightpanel.update(this.clone(true)).insert(
            this.description.insert(
                ' <a href="' + this.link + '">read more</a>'
            )
        );
    });
});

Now the headlines are all in the leftpanel box, the rightpanel box is empty, and if you click on any of the headlines, the headline and teaser will appear, followed by the read more link.

The only decision left is what to do with the rightpanel when the page initially loads. If you want the first story to load, you would do something like this:

var story = stories.first();
rightpanel.update(story.clone(true)).insert(
	story.description.insert(
		' <a href="' + story.link + '">read more</a>'
	)
);

You could also change first() to [rand(stories.length - 1)] and get a random story from the list.

Other details you could add would be to highlight the headline you’re showing on the left list.

Getting back to my premise here – the reason why you would put all the content into the page at first load is so that Google (which does not execute JavaScript when indexing your page) sees all of it, rather than just one story.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Oh, and the random thing, I made a tiny error with that, would have been fine PHP syntax, but not for JavaScript. Here’s how to do that in JavaScript:

stories[Math.floor(Math.random() * stories.length)];

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi waltd. Thank you for the quick reply and the detailed explanation. . I’m not able to try it out now but i will soon. I will let you know how it goes. Thanx again!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You’re welcome. I tried this out, and spotted one other issue – the way I was adding the read more links earlier, each time you clicked on the header to load the story, you would end up with another read more link at the end of the story. Keep clicking and the entire box would fill up with links. Here’s a corrected version:

This also has the indicator of which header is currently loaded, using the classname ‘active’. Style that up to your liking.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,

I’ve been trying your options out, but i can’t seem to get it to work. I’ve tried the first code you gave me, and the last one. but both end up in 3 little lines in the left panel and nothing in the right. I have the feeling that I’m missing something. I put the page I’m working on online:

http://shizihou.nl/eng_test/news_test.html

could you take a look at the code and point me in the right direction.

sorry and thanx!!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Don’t be sorry, change this line:

' <a href="' + this.link + '">read more</a>'

to read as this:

' <a href="' + elm.link + '">read more</a>'

And then, in your leftpanel box, be sure to enter some text – any
text – so that you don’t end up with a list of headers in 1px type,
as you have currently. (Freeway makes the font style in empty HTML
boxes 1px, and there’s no way to disable this behavior.) If you really
want this box to be empty except for your list of links, you still
need to add some text to it, but change the code very slightly. Change
this line:

stories.each(function(story){

to read:

leftpanel.update();
stories.each(function(story){

…(you’re adding a line before it, not changing that line).

This will clear out the leftpanel box before inserting the headlines.

Walter

On Apr 25, 2011, at 5:14 PM, wfa.vanleeuwen wrote:

Hi Walter,

I’ve been trying your options out, but i can’t seem to get it to
work. I’ve tried the first code you gave me, and the last one. but
both end up in 3 little lines in the left panel and nothing in the
right. I have the feeling that I’m missing something. I put the page
I’m working on online:

http://shizihou.nl/eng_test/news_test.html

could you take a look at the code and point me in the right direction.

sorry and thanx!!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options