Skip Navigation

[Resolved] Underline the current page out of a vpwiev list

This support ticket is created 6 years, 11 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.

Tagged: 

This topic contains 17 replies, has 2 voices.

Last updated by Oniromancer 6 years, 11 months ago.

Assigned support staff: Waqas.

Author
Posts
#339234

Hi

using this loop

	<wpv-loop>
		[wpv-post-link]
	</wpv-loop>

with a filter, I am visualising a menu of pages from a certain category.
This is working fine.

Now I would like to underline (or anyway change the css of the font) the post-link of the current page.

For example, having a list of pages as a menu:
Page1, Page2, Page3
I would like to have Page2 with a different color when the user is actually viewing Page2.

thanks.

#339334

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I suggest taking a look at https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ about how you can use Conditional HTML Output in Views. Also see Views Short Codes list at https://toolset.com/documentation/views-shortcodes/ for available short codes.

Please notice that you may need to use some custom code to grab the current page URL or Slug and then compare it with the current item in loop. Please see following resources:

- http://wordpress.stackexchange.com/questions/42117/how-to-retrieve-the-slug-of-current-page
- https://codex.wordpress.org/Function_Reference/is_page

If you are using a custom short code or function to achieve this, remember to register your function or short code under Views -> Settings -> Compatibility -> {relevant section for short code or function}

#339391

Hi
I tried this code with no luck

<wpv-loop>
          [wpv-post-link]
</wpv-loop>
[wpv-conditional if="('[wpv-post-link]' eq current_post_title() )"]<em>[wpv-post-link]</em>[/wpv-conditional]

I registered the function

function current_post_title() {
        $rio = get_the_title();
        return $rio;
}
#339549

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please use [wpv-post-link] and output of the current_post_title() without the [wpv-conditional]? So you can compare if both are returning the identical values.

Please remember that get_the_title() returns the sanitized title for the post, while [wpv-post-link] returns the link to the post (https://toolset.com/documentation/views-shortcodes/#wpv-post-link).

You need to have identical values to compare it successfully. Please look for other possible short codes at https://toolset.com/documentation/views-shortcodes/

#339658

Hi, yes I used the slug and all works now

the problem is now with the loop.

	<!-- wpv-loop-start -->
		<wpv-loop>
		[wpv-post-link]
		</wpv-loop>
	    [wpv-conditional if="('[wpv-post-slug]' eq current_post_slug() )"]<em>[wpv-post-link]</em>[/wpv-conditional]
	<!-- wpv-loop-end -->

This correctly outputs the post-link as italic, but twice. If I put it inside the loop then they will all come out formatted.
I need an else-if statement to make it work but i have no idea how to do it.

#339845

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Unfortunately, there's no "else" part in [wpv-conditional] short code. However, you can use NOT or ne operator to negate a test. Please see https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ for more information.

#340117

Its till not clear how should I proceed here.

Even using a negation doesnt allow to format the current post on the array.

      	[wpv-conditional if='("[wpv-post-slug]" ne current_post_slug() )']<em>[wpv-post-link]</em>[/wpv-conditional]

What I am trying to do here, is select the current page inside the <wpv-loop> and format it differently from the others.

thanks

#340162

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Based on the 'eq' condition, which worked fine for you, please consider following code:

<!-- wpv-loop-start -->
    <wpv-loop>
        [wpv-conditional if="('[wpv-post-slug]' eq current_post_slug() )"][wpv-post-title][/wpv-conditional]
        [wpv-conditional if="('[wpv-post-slug]' ne current_post_slug() )"][wpv-post-link][/wpv-conditional]
    </wpv-loop>
<!-- wpv-loop-end -->

Please notice the 2 [wpv-conditional] short codes used within the loop. The first condition checks if the slug of the post in loop matches the current_post_slug(), then it outputs just the Post Title. The second conditional checks if it does not matches (not equal to), then it outputs the Post Link.

This is how you actually take advantage of an else-if part, which is not available in [wpv-conditional].

I hope this will help fixing the issue.

#340207
Screen Shot 2015-10-15 at 12.12.55.png

Ah yes of course. I was thinking about nesting, couldnt see the solution. Thank you.

Strange enough, the condition eq is always true though.
While the ne is always false.

The View selects a post type with the filter in the attached image.

#340256

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can I ask for a temporary access to your site? So I can look for more details.

I have enabled your next reply as private, please input all details in that area. Please mention the links to the pages, views, forms, CPTs and configurations in question.

Please take a backup of your site, before proceeding.

#340434

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing the details. Please allow me some time to work on this. I will update you as soon as I find a solution.

#340479

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I have looking into your theme and Views from WPAdmin, but looks like I need to see the code for current_post_slug() function also. I may also need to add/alter some code in functions.php. I don't see the Editor and Plugins enabled via the access you provided.

I have set your next reply as private again, please allow me to edit functions.php via WPAdmin or FTP. As well as, the access to plugins page.

#340726

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing the FTP details. Please allow me some time to look into the code. I will update you as soon as I find a solution.

#341044

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Unfortunately, I am not able to edit any of the file (in plugin folder as you mentioned), nor under the theme's folder. So I can not edit the function or can implement some code experiments to make it work.

Please make either of the locations writable so I can proceed further.

#341054

Hi

I've logged in with your credential and I was able to read and write the files.
I've reset the server permissions anyway. This should work now, as on the server side everything looks good. Could you try again? thanks