Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#13 2007-10-30 07:12:31
- ferenczi
- Member
- Registered: 2005-01-31
- Posts: 67
Re: Returning current article id/active article
Gocom, I wanted to thank you for responding so promptly. Alas, this isn’t working for me. Which suggests that I must be doing something else wrong or fundamentally misunderstanding something. I wanted to really try and make sure I understood and was implementing what you said before responding immediately just to report that I wasn’t having any luck.
I’ve got a basic two-column page. On the left side, a video (flv) appears, selected from a list in the right column. Here’s how that’s set up.
<txp:chh_article form="videoblock" limit="1" sortby="Title" sortdir="asc" pgonly="0" section="media" excerpted="1" listform="videoblock" />
The list in the right column is called thus:
<div class="excerpts">
<ul>
<txp:article_custom section="media" listform="excerpt_list" sortby="Title" sortdir="asc" limit="10" />
</ul>
</div>
And here’s my excerpt_list form (type=link), where I tried to implement what you suggested:
<txp:rvm_if_this_article><span class="active"></txp:rvm_if_this_article>
<li><a href="<txp:permlink />"><txp:title /></a></li>
<txp:rvm_if_this_article></span></txp:rvm_if_this_article>
And the corresponding style:
.active {
color: $myorange;
}
What am I misunderstanding?
Offline
#14 2007-10-30 08:43:20
- ferenczi
- Member
- Registered: 2005-01-31
- Posts: 67
Re: Returning current article id/active article
And this is what would make the most sense to me, as my excerpt_list form, but this isn’t working, either:
<txp:rvm_if_this_article>
<li class="active">
<a href="<txp:permlink />"><txp:title /></a></li>
<txp:else />
<li class="inactive">
<a href="<txp:permlink />"><txp:title /></a></li>
</txp:rvm_if_this_article>
Offline
Re: Returning current article id/active article
That can be done shorter:
<li class="<txp:rvm_if_this_article>active<txp:else />inactive</txp:rvm_if_this_article>">
<a href="<txp:permlink />"><txp:title /></a>
</li>
If it doesn’t work, post a tag trace.
Offline
#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
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
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
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
Re: Returning current article id/active article
TXP adds rel=“bookmark” when using the permlink function.
Offline
Offline
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