Go to main content

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
Archived 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
Archived 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

#11 2007-10-27 20:03:15

ferenczi
Member
Registered: 2005-01-31
Posts: 67

Re: Returning current article id/active article

I would like to do exactly what coleh is doing

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).

but can’t seem to wrap my mind around how to make it work. Have installed ruud’s plugin and it’s active. I know this is probably so straightforward, and I apologize, but could someone please explain it in very simple terms?

Right now this is how the list of articles is being called in the page template:

<txp:chh_article_custom section="media" listform="excerpt_list" sortby="Title" sortdir="asc" limit="10" />

and this is how I tried to implement the plugin:

<txp:rvm_if_this_article><span class="active">
<txp:chh_article_custom section="media" listform="excerpt_list" sortby="Title" sortdir="asc" limit="5" /></span></txp:rvm_if_this_article>

Can someone explain what I’m doing wrong?

Offline

#12 2007-10-27 21:04:54

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Returning current article id/active article

ferenczi,

Put <txp:rvm_if_this_article></txp:rvm_if_this_article>-tags inside the article-form, in this case excerpt_list. In example:

<txp:rvm_if_this_article><span class="active"></txp:rvm_if_this_article>
	<!-- Your article code here -->
<txp:rvm_if_this_article></span></txp:rvm_if_this_article>

Cheers!

Last edited by Gocom (2007-10-27 21:05:22)

Offline

Board footer

Powered by FluxBB