Accueil › Toolset Professional Support › [Résolu] Underline the current page out of a vpwiev list
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.
Marqué : Views plugin
This topic contains 17 réponses, has 2 voix.
Last updated by Oniromancer Il y a 6 années et 9 mois.
Assigned support staff: Waqas.
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.
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}
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; }
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/
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.
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.
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
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.
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.
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.
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.
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.
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.
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