khjiang

Active page menu item in a page list

Vote 0 Votes

I am a beginner of Movable type. I am trying to set up menus of all pages that are not in any folders. As far as I know, the menu of pages can be generated as

<MTPages no_folder="1">
<MTPagesHeader><ul class="widget-list"></MTPagesHeader>
<li class="widget-list-item"><a href="<$MTPagePermalink$>" title="<$MTPageTitle$>"><$MTPageTitle$></a></li>
<MTPagesFooter></ul></MTPagesFooter>
</MTPages>

Now the question is how to give a "active" class to the page that is being displayed?

I appreciate for any feedback.

Reported on Movable Type 4.3

8 Replies

| Add a Reply
  • You will have to set a variable on the page template and then to use an if statement which to test if that variable is equal to the page name from your menu and if it is to display a CSS class for your link.

    Then you will have that class defined on your stylesheet with whatever active page formatting you like.

  • Thanks for quick reply, Mihai. Here is how I list pages:

    <mt:Pages folder="how-to-save" sort_by="title" sort_order="ascend">
    <li class="page page-<$mt:PageID$>"><a href="<$mt:PagePermalink$>"><$mt:PageTitle$></a></li>
    </mt:Pages>

    The issue here is that I don't know how to add MT "If condition" to set CSS class for active page.

  • I wasn't able to see what coding you're using.

    You have to strip the angle brackets.

    Just replace "<" with "&lt;" and ">" with "&gt;".

  • Thanks for suggestion. Here is my code that list pages in "how-to-save" folder:

    <mt:Pages folder="how-to-save" sort_by="keywords" sort_order="ascend">
    <li class="page page-<$mt:PageID$>"><a href="<$mt:PagePermalink$>"><$mt:PageTitle$></a<</li>
    </mt:Pages>

    I don't know how to add MT "If condition" to set a specific CSS class for the active page.

  • You have to set a variable, but do it before the mt:Pages loop.

    <mt:SetVarBlock name="current_page"><mt:PageID></mt:SetVarBlock>

    Then, add the following inside your mt:Pages loop:

    <mt:If tag="PageID" eq="$current_page"> class="active"</mt:If>

    Like this:

    <mt:Pages folder="how-to-save" sort_by="keywords" sort_order="ascend">
    <li class="page page-<$mt:PageID$>"><a<mt:If tag="PageID" eq="$current_page"> class="active"</mt:If> href="<$mt:PagePermalink$>"><$mt:PageTitle$></a<</li>
    </mt:Pages>

    This is going to add class="active" for your page links.

    You will have to create this class on your CSS document and give it whatever characteristics you like.

  • Thanks, Mihai. It works perfectly. One more question: Is there a way to add "first" class to the first item and add "last" class to the last item in the page list? In our design, the top menu and bottom menu have curve. Thus I have to assign a special class to them.

    Thanks again for all helps.


  • You could use the following conditional tags to check if the page is first or last and display something, such as your class.

    i.e.

    <mt:If name="__first__">this is first</mt:If>

    <mt:If name="__last__">this is last</mt:If>

    Kind Regards,
    Mihai Bocsaru

    ----------------------------------
    Web Development
    Movable Type Consulting
    Six Apart Partner

    http://www.pro-it-service.com/
    ----------------------------------

    Movable Type Demo
    http://www.movabletypedemo.org/

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1774 6167

Last Topic: Template modules by Zielun on Feb 16, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1434 5088

Last Topic: Maintenance announcement by Nick on Feb 17, 2012

695 2912

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

174 740

Last Topic: Captcha images rendering slowly by ScottM on Feb 12, 2012

190 568

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012