I've got a site where it shows different content dependent on the url segments (categories eugh!) but as there can be up to 4 url segments, any of which could have pagination, i want to be able to say not if segment is a pagination segment.

Obviously i could do {if (segment_4 != '') && segment_4 != 'P25' && segment_4 != 'P50'} but pagination could be any value in theory. So, is there a way of saying "where segment_4 is not a pagination segment"?


4 Answers 4


Use Switchee. It supports regular expressions, and example on devot:ee page shows how to use that to check for pagination.


I use Switchee to detect pagination except in cases where I just can’t work Switchee into the template, in which case I use MD Detect Page Type.

Switchee example:

{exp:switchee variable = "{segment_4}" parse="inward"}
    {case value="''"}
        Not Paginated
    {case value="#^P(\d+)$#"}
        This is Paginated

MD Detect Page Type example:

{exp:md_detect_page_type url_segment="{segment_4}"}
    {if pagination_page == TRUE}

The simplest way is to use Rob's Mo Variables which comes with some very useful global variables for use in your templates including "{if paginated}". This also makes it very easy to see what the code is doing when you re-visit it at a later date.

Failing that I'd fall back to Switchee. -----

  • This is handy. I've used {if page_offset == 0}...{/if} to distinguish the first page of a pagination set from the rest of the pages of that set as well.
    – yuvilio
    Commented May 2, 2013 at 20:53

Switchee will work in some cases, but I've also been using the very versatile Mo'variables successfully. Among other things, it has a handy {if_paginated} conditional that checks whether pagination appears in your segments. Pleanty of other goodies as well in terms of working with segments.

EDIT: code example (not at my desk so cannot test)

{if segment_4 != ""}
    {if not_paginated}
        stuff to do

When working with categories, I have also found GWcode Categories to be invaluable. Makes your life a hell of a lot easier.

  • Ha, beat me to the trigger. :)
    – Ian Young
    Commented Jan 17, 2013 at 13:58
  • I have been trying it, but it's not working as expected in my scenario. I want to do: {if (segment_4 != '') && segment_4 not_paginate} but any combo i've tried hasn't worked. Any ideas on how to modify this tag to work with the mo variable ext? Commented Jan 17, 2013 at 14:00
  • I think mo'variables conditionals are simple ones, meaning I don't think they can be used like you suggest here. Have you tried a nested approach? Updated my answer with code. Commented Jan 17, 2013 at 14:09
  • Hmm, i don't think this is going to work in my scenario, i'm going to have to go for switchee i think. Thanks though, really appreciate your input!! Commented Jan 17, 2013 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.