Home > theming > Get current taxonomy in template_preprocess_html()

Get current taxonomy in template_preprocess_html()

November 6Hits:3
Advertisement

I have a custom field on my taxonomy that I would like to access in template_preprocess_html(). How do I get the current taxonomy id, in Drupal 8, on a taxonomy listing page?

Answers

First, check if the route is for a taxonomy term; then, get the term ID.

if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical') {
  $term_id = \Drupal::routeMatch()->getRawParameter('taxonomy_term');
}

Related Articles

  • Get current taxonomy in template_preprocess_html()November 6

    I have a custom field on my taxonomy that I would like to access in template_preprocess_html(). How do I get the current taxonomy id, in Drupal 8, on a taxonomy listing page? --------------Solutions------------- First, check if the route is for a tax

  • SharePoint 2010 Taxonomy and URLsMay 20

    Can anyone explain if there is a relationship in SharePoint 2010 between the meta data services/taxonomy and the url of list items? --------------Solutions------------- If you tag pages (not items) in SharePoint, this is done by URL. If the URL chang

  • Not sure how to programmatically filter by taxonomy metadata in my custom search webpartJuly 9

    I have pages in a pages library on a publishing site which have a managed metadata (taxonomy) field in their content type. I want my custom search webpart to read the taxonomy set on its parent page (I can do this fine) and then query against a speci

  • Why are Taxonomy Term Stores always empty?July 16

    Using the following code I should be able to access the Taxonomy Term Stores: $site = new-object Microsoft.SharePoint.SPSite("http://localhost") $session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) $session.TermStores.Count

  • Taxonomy field doesnt always show up in CQWP filterJuly 30

    I am using two new features in CQWP to list "related items" in a web part: Taxonomy field filtering is used to match the current pages taxonomy value given dynamically by [PageFieldValue:MyTaxonomyField]. This works like a charm, as long as i po

  • Adding Custom Field to Taxonomy Input :PanelSeptember 6

    I am looking to achieve something which I figured would be fairly simple to accomplish but it seems there are no real examples available to achieve my needs. Essentially I have a custom post type of "Articles" for this custom post type I have a

  • Custom Metabox with Taxonomy Dropdown - Saving IssueSeptember 7

    My goal was simple --- to create a custom post type with a custom metabox with a simple drop down list of taxonomy terms instead of utilizing the tags or checkboxes. The reason was to ensure that the editor can only select a single term from the taxo

  • Fixing Pagination with Custom Taxonomy ArchiveSeptember 11

    I've been trying to set up a way to write posts in a series on my site. The idea is that each post can belong to a different series in a custom taxonomy. I've gotten just about everything set up the way I want it ... with one exception. Registering t

  • Saving Taxonomy TermsSeptember 14

    I have an interesting problem which I hope someone can quickly answer. I have created my own metabox which, based on "MY METABOX CODE" (list below) is correctly displaying a dropdown list of all my terms within the "event_types" taxono

  • Custom Post Type Archives by Date and TaxonomySeptember 15

    Lets use the classic example of a custom post type called "movies", with its own taxonomy called "genre". By registering the custom post type (with a "movie" slug), the permalinks are already set up for <domain>/movie/a

  • Custom Taxonomy list: how to make "choose from most used" default to open, checklistSeptember 24

    I'm doing a site for a wine importer. The wines have many custom taxonomies (type of wine, import/domestic, etc.) When adding a wine, the taxonomies show up in the right column but not the way I'd like. The default is a form input field with a link u

  • Sorting for each custom taxonomySeptember 25

    I have a custom post type called Baseball Players which contains teams, positions, and a league taxonomy. A team consists of the team name, logo, description, and coach. A position just consists of the name. A league consists of a name, logo, descrip

  • Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?September 27

    (Moderators note: Was originally titled "How to get_posts of a custom post type that is in two custom taxonomies?") I have a custom post type that has two taxonomies which are separate, one called "Project Type" and one called "Pa

  • rewrite rules for custom post-type with a custom taxonomySeptember 29

    I have a custom post type ('post' capabilities) called EVENTS and a custom taxonomy called VENUES (hierarchical). I want to be able to set the post's url to domain.com/my-events/%TAXONOMY%/%POST-TYPE% kind of like category/post-name, but it doesn't s

  • Get the 'slug' of a custom taxonomyOctober 4

    Use case: I have a custom post type of 'show' for a music venue. In the sidebar we want to display any related 'show' to the current one on single-show.php. They will be related by a custom taxonomy of 'genre'. I figured I could dump the custom taxon

  • List Posts of a Custom Post Types Ordered by Terms of a Custom Taxonomy?October 5

    I've created a custom post type and custom taxonomy. I can now create a new post and associate it with a custom category. The problem is listing these news post types. This: $loop = new WP_Query( array( 'post_type' => 'sobeedesce' ) ); while ( $loop-

  • List taxonomy terms as linksOctober 5

    How can I make a list of links of all the taxonomy terms I'm using? For example, I have a taxonomy of Manufacturers with terms of Honda, Ford, etc. I want to list out those terms as links. --------------Solutions------------- My apologies. After some

  • Include custom taxonomy term in searchOctober 6

    I have two custom taxonomies applied to two custom post types. the terms list on the sidebar just fine and will list all posts associated with it. However, if you search one of the terms in specific, it doesn't bring up a post with that term. Example

  • Custom search using custom fields, post type, and custom taxonomy October 6

    I have two custom taxonomies applied to two custom post types. the terms list on the sidebar just fine and will list all posts associated with it. However, if you search one of the terms in specific, it doesn't bring up a post with that term. Example

  • Displaying Posts Related to Other Posts by a Taxonomy Term?October 6

    I have a custom post type for musician's profiles, and a taxonomy for their location (categorised hierachically into Countries and then Cities). On the musician's individual profile pages I need to display a list of musicians in the same city (i.e. t

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 17 q. 0.529 s.