Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
soo_if_frontpage: is this a section front page?
Similar to the glx_if_frontpage
tag from the no-longer-supported “ glx_if
plugin. Most of glx_if
’s functionality is now available through core Txp tags, but not this (well, not without an absurd stack of conditional tags). To glx_if_frontpage
it adds txp:else />
compatibility, and a couple of attributes for more control.
soo_if_frontpage
evaluates to true
if the current page context is:
- an article list, and;
- not search results, and;
- not a listing of articles by category, and;
- not a listing of articles by author, and;
- not a listing of articles by month, and;
- not an image page, and;
- in one of the sections listed in
section
(defaults to the ‘default’ section only), and - (optionally) a single-page list or the first page of a multi-page list, if the
pg
attribute is set.
Note: as of version 0.1.4 you can use section="*"
as a shortcut to include all sections (including default). Thanks to alanfluff for the feedback.
Why? I was cleaning out some Txp cruft and was going to get rid of this little plugin, which I’ve been using privately for years. But re-discovered that it is genuinely useful for at least one small but important situation: styling the Home link in a nav bar. I want to give this an “active class” only if it is truly the home page, i.e. <http://my-site.com/>
. Very cumbersome to do this with only core Txp tags.
Last edited by jsoo (2011-01-14 21:23:46)
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
Released v 0.1.1.2, adding month and author to conditions to check against.
Code is topiary
Offline
#3 2009-09-25 01:18:54
- xavoy
- New Member
- Registered: 2009-09-25
- Posts: 2
Re: soo_if_frontpage: is this a section front page?
Thanks mate, you’ve saved me writing some messy conditionals :)
Offline
Re: soo_if_frontpage: is this a section front page?
No worries!
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
Jeff, i’ll need to start recommending this plugin. I’ve been using the glx_if for so long that it is the first which comes to mind when people are asking for such separation. I just replaced it with yours and it not only works, it also performs faster.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: soo_if_frontpage: is this a section front page?
Thanks Jeff, I also succumbed on one site and used it! Very useful!
Offline
Re: soo_if_frontpage: is this a section front page?
colak wrote:
it also performs faster.
Curious: by what measurement? Although the plugin is much smaller, having just the one tag, when it comes to the actual functions soo_if_frontpage
has more code (and an additional function call) compared to (individually) glx_if_frontpage
, glx_if_not_frontpage
, glx_if_section_frontpage
, or glx_if_not_section_frontpage
. Of course it’s faster for typing being able to use <txp:else />
;)
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
When i open site.ru/blog/
plugin returnes TRUE. I think it should say FALSE
Just found – a little code changing made it work:
The result is:
return parse(EvalElse($thing,
( $section ? in_list($pretext['s'], $section) : true ) and
( $pg ? $pretext['pg'] < 2 : true ) and
( $pretext['s']=='default' ? true : false) and
empty($pretext['c']) and empty($pretext['q']) and empty($pretext['author'])
and empty($pretext['month']) and $is_article_list));
Than at section pages plugin returns false, as expected
Last edited by the_ghost (2010-03-29 14:12:45)
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: soo_if_frontpage: is this a section front page?
Victor, thanks for catching this. I managed to miss your post at the time.
Version 0.1.3 now available, fixes the bug found by Victor.
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
Version 0.1.4 released.
You can now use section="*"
as a shortcut for specifying all sections (including default).
Thanks to alanfluff for the feedback.
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
Make that version 0.1.5 0.1.6. No behavioral change from 0.1.4, just a documentation update and some code cleaning.
Last edited by jsoo (2010-10-08 12:37:09)
Code is topiary
Offline
Re: soo_if_frontpage: is this a section front page?
Version 0.1.7 available
Documentation update only. (Thanks to admi for the suggestion.)
Code is topiary
Offline