Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-08-16 10:56:56

coleh
Member
From: Edinburgh, UK
Registered: 2007-08-16
Posts: 28
Website

Returning current article id/active article

Hi
I’m a newbie with txp but finding my way around thanks to the invaluable new Friends of Ed book.
Was wanting to apply an active_class to a custom article list. Gather from the documentation this isn’t possible so was thinking about how else this might be achieved.
Considered using a form with an if_article_id tag but that would require knowing the current article id. Is there a way of returning the active/current article id within a from or an existing solution that would avoid me reinveting the wheel?

Thanks in advance,

Cole


Jack of all trades, Doctor of one

Offline

#2 2007-08-16 11:05:32

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Returning current article id/active article

See Textbook
I think you’re looking for <txp:article_id />

Offline

#3 2007-08-16 11:12:12

coleh
Member
From: Edinburgh, UK
Registered: 2007-08-16
Posts: 28
Website

Re: Returning current article id/active article

thanks Ruud
Anyone got any suggestions as to how I might use article_id to inform the id attribute of an if_article_id tag?

Cole


Jack of all trades, Doctor of one

Offline

#4 2007-08-16 12:19:05

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Returning current article id/active article

Wouldn’t that condition always be true?
That would be like saying: “if current article id is equal to the current article id, do this”

Offline

#5 2007-08-16 13:17:48

coleh
Member
From: Edinburgh, UK
Registered: 2007-08-16
Posts: 28
Website

Re: Returning current article id/active article

Don’t think I have explained myself very well and am rapidly exposing my ignorance of txp.
When within any section of a particular site I want to post a list of articles belonging to that section as a navigation list linking to the articles in question (titles only).
I want to apply a different treatment for an article in that list that is currently being shown (e.g. not hyperlinked or made strong).
How might I achieve this?
Sorry if this is obvious – still finding my way around txp.
Cole


Jack of all trades, Doctor of one

Offline

#6 2007-08-16 15:48:35

marios
Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Returning current article id/active article

Javascript is your friend here.
In other words, the best solution is ( since it’s presentational anyway ) attach an active class to the first child of the article_list parent division.
Txp uses jquery. (which you could use I think)
Or you could use moofx.

regards, marios


⌃ ⇧ < ⌃ ⇧ >

Offline

#7 2007-08-16 16:15:59

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Returning current article id/active article

Put this in your article_custom form:

<txp:php>
  global $pretext;
  echo if_article_id(array('id' => $pretext['id']), '
     <!-- put html code + txp tags here for displaying the current article -->
     <txp:else />
     <!-- put html code + txp tags here for displaying the other articles -->
  ');
</txp:php>

The txp:article_id tag can’t be used in this situation, because if you use it inside an article_custom form, it would always be set to the article id of the article currently being processed by article_custom.

Last edited by ruud (2007-08-16 17:01:11)

Offline

#8 2007-08-16 17:13:07

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Returning current article id/active article

Ooh, now without even testing the code, lets try that as a plugin

download plugin

Last edited by ruud (2007-08-16 17:17:07)

Offline

#9 2007-08-16 20:10:18

coleh
Member
From: Edinburgh, UK
Registered: 2007-08-16
Posts: 28
Website

Re: Returning current article id/active article

Hi Ruud
Great stuff – the PHP code and plugin work a treat!
Stirling effort and many thanks,

Cole


Jack of all trades, Doctor of one

Offline

#10 2007-09-20 20:49:47

Jeff_K
Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

Re: Returning current article id/active article

Works like a treat! I always have to write php code for this type of thing. many thanks!

Offline

Board footer

Powered by FluxBB