Tip: How to get the category/section/topic ID using breadcrumbs? | Community
Skip to main content

Tip: How to get the category/section/topic ID using breadcrumbs?

  • July 31, 2021
  • 0 replies
  • 0 views

Ifra

Prerequisite:

Templates: category, Section, Article, Community Post 

Use: Random

Hi to all,

Here, I am sharing a simple tip  that if anybody need in urgent call like middle of the customization project so he/she can use this. The given regex can be used to get the IDs from the breadcrumbs and user can check the IDs with 'if' condition and do something  using JS, etc.

To get category ID from breadcrumbs.

<script>   
var getID = $('.breadcrumbs li:nth-child(2) a').attr('href').match(/[0-9]+/)[0]  
</script>

 

 

To get section ID from breadcrumbs.

<script>   
var getID = $('.breadcrumbs li:nth-child(3) a').attr('href').match(/[0-9]+/)[0]  
</script>

 

The above script code need to add on the template inside the script tags.

 

There are another ways to get the IDs by search-bar as in my previous post and this one is also from those ways :)

 

Thanks