Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-10-27 18:10:08

Game Makker
New Member
Registered: 2006-10-27
Posts: 3

Javascript and Posts

Hi I am new to the forum and textpattern and loving it so far.
I am looking for a way in which I can display 5 of the latest posts but have only the body of the extreme latest show. I am aiming to use Script.aculo.us to make the titles of all of the posts either hide or reveal the posts body.

Does anyone know how to get started. Help would be hugely appreciated.

Offline

#2 2006-10-28 00:33:26

jdykast
Member
From: Tennessee
Registered: 2004-12-30
Posts: 119
Website

Re: Javascript and Posts

Game Makker I began answering your post about three times and each time I ran into something I didn’t think of but I think I have a good idea now. I’m not sure how familiar you are with Scriptaculous and Textpattern so I hope I’m not telling you stuff you already know.

First, check out Introduction to Scriptaculous Effects at 24ways.org. This is a pretty simple intro to Scriptaculous. If you’re just wanting a simple accordian effect this article should do the trick for you.

One of the problems that you’ll run into is that each element that you want to run your effect on needs to have a unique id (which ids need to be by definition) so that the script knows who to act on. There are probably better ways of doing it but the only way I could think of to give each article posting on your page a unique id was to use the following code in your article form:

<div id="<txp:article_id />">...</div>

Then you add the same Textpattern tag to the javascript like this:

<h2 onclick="javascript:Effect.Combo('<txp:article_id />');"><txp:title /></h2>

I’d recommend building a form for your articles that looks something like the following:

<div class="articlePost">
  <h2 onclick="javascript:Effect.Combo('<txp:article_id />');"><txp:title /></h2>
  <div id="<txp:article_id />" style="display:none;">
    <txp:body />
  </div>
</div>

The form for the first article would need to be different because you don’t want the article to be hidden so I would remove all of the javascript stuff from the h2 and remove the styling from the interior div.

Then on the page that you want to display these articles you could use something like the following:

<txp:article limit="1" form="visibleArticleForm" />
<txp:article limit="4" offset="1" form="hiddenArticlesForm" />

The offset and limit attributes divide the articles into two groups like you wanted and the forms should do the rest if you have followed the basic instructions from the 24ways article.

Good luck and sorry for the massive reply.

Offline

#3 2006-10-29 21:22:26

Game Makker
New Member
Registered: 2006-10-27
Posts: 3

Re: Javascript and Posts

Your a star. Ill try and tell you if it works.. Busy atm but it sounds good thanks for the help :D

Offline

#4 2006-10-29 23:04:58

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Javascript and Posts

There is also the option of using a single article tag and a conditional in the form, if you always want only the last article in the list to show a different display.

txp:if_last_article

Offline

#5 2006-10-31 17:35:39

jdykast
Member
From: Tennessee
Registered: 2004-12-30
Posts: 119
Website

Re: Javascript and Posts

It’s funny – I ran into that tag about 3 days after writing that first post. There always seems to be “new” Textpattern tags popping up. I’m pretty impressed with the flexibility built into TXP.

Offline

#6 2006-11-01 20:28:34

Game Makker
New Member
Registered: 2006-10-27
Posts: 3

Re: Javascript and Posts

Same. I recently moved from WP and I am soo pleased I did. The amount of work to customise WP is huge in comparison to TXP.

Offline

Board footer

Powered by FluxBB