Skip Navigation

[Resolved] Dynamically format taxonomy term in view based on current taxonomy archive

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

This topic contains 2 replies, has 2 voices.

Last updated by liatG 6 years, 3 months ago.

Author
Posts
#1108489
Terms within each chapter loop.png
Sidebar item to be dynamically formatted based on current page.png

The link to my site is hidden link

I have a nested taxonomy view set up in the sidebar that Christian helped me set up.
I want to bold and un-link the taxonomy term that is the same as the taxonomy archive the user is on.

For example on hidden link I would want the sidebar item "Ch. 2 Anatomy of a Pattern" to be bold and not a link. Basically this would show the user what page they are currently on in the context of the sidebar.

See screenshot.

The views that make up this sidebar view are:

hidden link
hidden link
hidden link

This last view (Terms Within Each Chapter) is where I would want the formatting to take place.

I've uploaded admin credentials in other support tickets if you want to take a look. I've attached a screenshot of the loop contents because they are very simple.

Can you tell me if there is a way to conditionally format the loop item based on the current taxonomy archive page displayed?

Thanks,
Liat

#1108790

You can use conditional HTML around the Shortcodes or HTML that produces the (currently linked) taxonomy term in the sidebar.

That conditional should check the current archive (best case, the last part of the URL), and if it is equal to the term's slug or temr's archive url, then it should not apply the HTML which produces the Link, and instead apply a Bold HTML

You can do this by following the steps below:

1. Register this Custom ShortCode in your Child Theme's Functions PHP:

function get_current_page_slug(  ){
global $wp;
	$current_slug = add_query_arg( array(), $wp->request );
	return $current_slug;
}
add_shortcode( 'return-current-slug', 'get_current_page_slug' );

The WordPress API used for this is here:
https://codex.wordpress.org/Shortcode_API

2. Register this Shortcode in Toolset > Settings > Front End Content > Third-party shortcode arguments

3. This ShortCode will now return any where where used, the current seen URL, minues the "hidden link" part.

4. This means, you can use it to check the current seen archive ([return-current-slug]) with this value:

my-classes/[wpv-post-taxonomy type="category" format="slug"]

If you require to return in the Shortcode only the very last part (this is needed if you have nested terms), then you need to use a slightly different ShortCode:

function get_current_page_slug(  ){
global $wp;
	$current_slug = add_query_arg( array(), $wp->request );
	$end_of_slug = strstr($current_slug, '/');
	return $end_of_slug;
}
add_shortcode( 'return-current-slug', 'get_current_page_slug' );

We remove whatever befor /, with hidden link.
That should return us only the last child of the chain of terms, as in /term_slug

So again you can now use this to compare to a value like:

/[wpv-post-taxonomy type="category" format="slug"]

The HTML conditional syntax itself is explained here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Please note that this instructions involve Custom Code that where tested locally but are not part of native Toolset Support.

If you require further assistance with the Custom Code, the Toolest Consultants would be there for:
https://toolset.com/contractors/

#1108842
Dynamically formatting sidebar based on URL.png

It worked!!!! Beda, you are the best. Thank you so much. I used the custom code, the shortcode, and the conditional HTML reference you gave me to achieve EXACTLY the result I wanted.

Here is the HTML code I included in the loop in case anyone else is wondering how to do it. This may not be the most elegant way, but it made sense to me as a beginner and it worked.

		<wpv-loop>
			<li style="text-indent: 0.7em">
              [wpv-conditional if="( '<em><u>hidden link</u></em>' eq '[wpv-taxonomy-url]' )"] <b>&#9658; [wpv-taxonomy-title]</b>[/wpv-conditional]
          [wpv-conditional if="( '<em><u>hidden link</u></em>' ne '[wpv-taxonomy-url]' )"] [wpv-taxonomy-link][/wpv-conditional]</li>
		</wpv-loop>

Screenshot of the final result attached. Thank you SO SO much.
Liat