Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2007-10-30 12:51:32

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

Re: Returning current article id/active article

Thanks, ruud. That doesn’t work, either.

post a tag trace

You mean this?

[edited out this flood of code because I misunderstood what ruud was suggesting]

Last edited by ferenczi (2007-10-30 21:39:56)

Offline

#17 2007-10-30 16:34:43

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

Re: Returning current article id/active article

First, please give more details about what exactly doesn’t work. Also post an URL to the page that demonstrates the problem. And a tag trace for that page.

Offline

#18 2007-10-30 18:31:30

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

Re: Returning current article id/active article

Successting also, to give some more details, URL to the page and tag-trace.

And basically, what is the code outputting. Because it could be something to do with the CSS-styling also, because at your example you were styling the active-class, not the link – so the color won’t change. As corrected:

li.active a {
	color: #CC0000;
	}

Cheers!

Offline

#19 2007-10-30 22:05:39

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

Re: Returning current article id/active article

Because it could be something to do with the CSS-styling also

Oh feck me. Stupid, stupid mistake. Thanks, Gocom.

Yes, it works.

Offline

#20 2007-10-31 17:22:25

danhoy
New Member
From: BC, Canada
Registered: 2007-06-02
Posts: 5
Website

Re: Returning current article id/active article

I searched for quite some time before I found the bits and pieces to put together this recipe for a dynamic sub navigation with a class=“active” attaching itself to the current menu item. This allows you to apply styling to the active menu item without having to hard code the links in your page (template) every time you add an article.

I use the txp:article_custom tag in combination with the rvm_if_this_article plugin to achieve this functionality.

I will give you a step by step scenario to accomplish the desired results. If my illustration seems painfully detailed, it is in an effort to make the information digestible to the novice TXP developer.

The sample scenario:

You have a “section” in your site called “about” which uses an “about” “page” (template).

First install and activate the following plugin: rvm_if_this_article
found here: http://vanmelick.com/txp/rvm_if_this_article.php

Within the “about” “page” you have the following two snippets of code—one for the navigation and one for the article output (novice note: you must have some articles assigned to the “about” “section”):

<ul id="subnav">
  <txp:article_custom form="subnav" limit="99" section="about" sort="Posted asc" />
</ul>

<div id="content"> 
  <txp:article form="static" limit="1" sort="Posted asc" />
</div>

The forms you are calling:

subnav (article-form):

<li<txp:rvm_if_this_article> class="active"</txp:rvm_if_this_article>><a href="<txp:permlink />"><txp:title /></a></li>

static (article-form):

<h2><txp:title /></h2>
<txp:body />

That’s it.

This will create the following html for your page (substitute your own articles).

<ul id="subnav">
  <li><a href="http://dynamicnav.local/about/about-article1">About Article#1</a></li>
  <li><a href="http://dynamicnav.local/about/about-article2">About Article#2</a></li>
  <li class="active"><a href="http://dynamicnav.local/about/about-article3">About Article#3</a></li>
</ul>

<div id="content"> 
  <h2>About Article#3</h2>
  <p>Article Content...</p>
</div>

Just style your .active links and you’re good to go.

btw: if there is a better way to do this now please post a tip in Texpattern Resources.
__________________________________________________________________

Side note: It beats adding the following type of hard-code to my template every time I create a new article just to get the class=“active” effect.

<li>
<a href="<txp:site_url />identity/shine-like-stars"<txp:if_article_id id="13"> class="active"</txp:if_article_id>>Shine Like Stars</a>
</li>

Although, it sure was a useful solution when I needed it.

Edit by Ruud: added some markup to make it easier to read.

Dan: Thanks Ruud, great plugin :-)

Last edited by danhoy (2007-11-08 20:42:56)

Offline

#21 2007-10-31 18:10:58

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

Re: Returning current article id/active article

TXP adds rel=“bookmark” when using the permlink function.

Offline

#22 2007-10-31 18:38:42

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

Re: Returning current article id/active article

And to include, if you want the rel="bookmark" go away, then change subnav to this

<li<txp:rvm_if_this_article> class="active"</txp:rvm_if_this_article>><a href="<txp:permlink />"><txp:title /></a></li>

Cheers!

Offline

#23 2007-11-01 04:53:59

danhoy
New Member
From: BC, Canada
Registered: 2007-06-02
Posts: 5
Website

Re: Returning current article id/active article

Ruud and Gocom:

Thanks for the answers!
I have been wondering how to do set up this kind of navigation for probably close to a year since I started tinkering with TXP. I guess I should visit the txp community more often :-)

Cheers

Last edited by danhoy (2007-11-01 04:54:36)

Offline

#24 2009-07-25 21:58:33

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Returning current article id/active article

Good Evening,

after some time spent with google i found this script, but there’s a little problem when I’m using it without an id given, it doesn’t show anything.
Opening a section just by using an url like: host.com/index.php?s=home the script is not returning any code.
If there is a numerical id given (e.g. index.php?s=home&id=2) it works fine for me.

(I am using the PHP-Code in a form, since I will use it just for one little menu I don’t want to install it as a plugin.)
The form looks like this:

bc..

<txp:php> global $pretext; echo if_article_id(array(‘id’ => $pretext[‘id’]), ‘ <b><txp:permlink><txp:title /></txp:permlink></b> <txp:else /> <txp:permlink><txp:title /></txp:permlink> ‘);
</txp:php>
<txp:if_last_article><txp:else /><font color=”#000000”> | </font></txp:if_last_article>

bq.

How can I fix my little Problem?

regards,
RipvanFish

Last edited by RipvanFish (2009-07-25 22:07:31)

Offline

#25 2011-02-02 05:44:12

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 726
Website Mastodon

Re: Returning current article id/active article

Hi there,

what can i do to display the active class, even if i access an article only as a non-individual one?

EXAMPLE
i have content code like this in a section called lala:

<div id=“lala_content”>
<txp:if_individual_article>
<txp:article limit=“1” />
<txp:else />
<txp:article_custom id=“2” />
</txp:if_individual_article>
</div>

and in a sidebar navigation i got this to mark the active article:

<txp:rvm_if_this_article><li class=“active_article”><txp:else /><li></txp:rvm_if_this_article>
<i><span class=“entry-title”><txp:permlink><txp:title /></txp:permlink></span></i></li>

This attaches the active class to the navigation entry correctly, as long as i access the article individually.

As soon as i manoever to the section without appending an article url-title in the URL (resulting in displaying the article with ID 2)
no active class for the first article in the navigation (which is ID 2) is displayed.

I get the same result, when instead using server variables.

Thank you very much for any suggestions.

Last edited by jayrope (2011-02-02 07:14:16)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#26 2011-02-02 11:53:51

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Returning current article id/active article

The point of article_custom is that it displays a list with no relationship to global article context. That works in both directions; the fact that you are displaying article #2 somewhere on the page using article_custom does not make it “active” in any general sense.

BTW you can use if_article_id instead of rvm_if_this_article, if I am correctly understanding what rvm_if_this_article does.

Is the navigation list based on article_custom?

BTW even though your scenario fits with the existing topic, it’s an old topic and you’re asking a new question pertaining to it — better to open a new topic.


Code is topiary

Offline

#27 2011-02-02 20:31:03

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Returning current article id/active article

jayrope wrote:

and in a sidebar navigation i got this to mark the active article:

<txp:rvm_if_this_article><li class="active_article"><txp:else /><li></txp:rvm_if_this_article> <i><span class="entry-title"><txp:permlink><txp:title /></txp:permlink></span></i></li>

What you want can be done, but how to do it depends on the code you are using for the navigation (using article_custom, section_list, something else?). Can you post the entire code of the navigation list?

Offline

Board footer

Powered by FluxBB