Skip Navigation

[Resolved] If current page not working in template file…

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display conditional output with current page template

Solution:
We have replaced [wpv-if] shortcode with [wpv-conditional] shortcode.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/if-current-page-not-working-in-template-file/#post-392475

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by thomasS-11 7 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#390998

Hello Guys.

Im currently using the following code to output my nav.

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ul id="main-nav" class="nav navbar-nav menu">
  <wpv-loop>
    <li [wpv-if evaluate="[wpv-post-id]=[wpv-post-id id="$current_page"]"]class="active"[/wpv-if] >
      <a href='[wpv-post-url]'>
        [wpv-post-title]
      </a>
      <div class="active-marker">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
      </div>
    </li>
  </wpv-loop>
</ul>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]

Problem is, the "active" class doesnt get added to the li item that is the current page item..
The REAL problem is in fact, that it does, but only some times (not knowing why and what makes it show only sometimes).. If it did not show at all, i would think it has something to do with the code, but since SOMETIMES it does, i really have a hard time knowing what it is..
The shortcode is not added to in the loop (of the template), but its added in header.php

I wanted to provide debug info, but could not find it anywhere since the ui/structure has been changed multiple times in the latest updates.

#391049

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

We have replaced [wpv-if] shortcode with [wpv-conditional] shortcode.

There is a detailed documentation regarding conditional output. Could you please go through the following Doc and try to resolve your issue.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#392465

Hi Minesh.

I tried updating the code, it works but the issue still persists. Im getting very sure this is a bug.

New code:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ul id="main-nav" class="nav navbar-nav menu">
  <wpv-loop>
    [wpv-conditional if="(empty($(wpcf-skjul-i-menu)) )"]    
    <li [wpv-conditional if="[wpv-post-id]=[wpv-post-id id="$current_page"]"]class="active"[/wpv-conditional]>
      <a href='[wpv-post-url]'>
        [wpv-conditional if="(NOT empty($(wpcf-menu-ikon)) )"]
        <img src='[types field="menu-ikon" output="raw"][/types]' class="menu-ikon" />
        [/wpv-conditional]
        [wpv-post-title]
      </a>
      <div class="active-marker">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
      </div>
    </li>
    [/wpv-conditional]
  </wpv-loop>
</ul>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]

It still does not add the class to the correct page.

#392475

I found the solution.

The code has been updated again.
For others who might experience the same issue, here it is:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ul id="main-nav" class="nav navbar-nav menu">
  <wpv-loop>
    [wpv-conditional if="(empty($(wpcf-skjul-i-menu)) )"]
    <li [wpv-conditional if="( '[wpv-post-id]' eq '[wpv-post-id id="$current_page"]' )"]class="active"[/wpv-conditional]>
      <a href='[wpv-post-url]'>
        [wpv-conditional if="(NOT empty($(wpcf-menu-ikon)) )"]
        <img src='[types field="menu-ikon" output="raw"][/types]' class="menu-ikon" />
        [/wpv-conditional]
        [wpv-post-title]
      </a>
      <div class="active-marker">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
      </div>
    </li>
    [/wpv-conditional]
  </wpv-loop>
</ul>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.