3 removed "Drupal" from the title; removed tags from the title; added a more explicit and less generic question
source | link

Best practices for displaying How do I display a taxonomy term, without a link, in a node template in Drupal 7?

Just started working with Drupal probably a week ago and I'm struggling to find a place that lists current best practices.

In learning, I've created a custom content type called storystory and a custom taxonomy called story_categorystory_category. In storystory I have a field_term_reference that relates the story_category to storyterm reference for story_category.

Problem: I can render a taxonomy term associated with a node however it automatically renders as a link to the urlURL alias instead of my custom taxonomy field.

Question: What are the current best practice techniques when trying to How can I display a taxonomy term with no link?

My current results: http://imgur.com/um6v459

I appreciate any helpresult is the following. Thanks all!


Here's my setup:

screenshot

Content Type:These are the fields for the StoryStory content up.

Custom Taxonomy:These are the fields for the Story Category vocabulary.

page--front.tpl.php This is my page--front.tpl.php template.

<main>
 
  <div class="container">
    <div class="row">
      <div class="col-sm-8">
 
        <?php // ------ impactful stories ------ // ?>
        <?php
          $impactfulStoriesQuery = new EntityFieldQuery();
 
          $impactfulStoriesQuery
            ->entityCondition( 'entity_type', 'node' )
            ->entityCondition( 'bundle', 'story' )
            ->propertyCondition( 'status', 1 )
            ->fieldCondition( 'field_impactful_story', 'value', 1, '=')
            ->propertyOrderBy( 'created', 'DESC' )
            ->range( 0, 2 );
 
          $impactfulStoriesQueryResults = $impactfulStoriesQuery->execute();
 
          if ( isset( $impactfulStoriesQueryResults[ 'node' ] ) ) {
            $impactfulStoriesNodeIDs = array_keys( $impactfulStoriesQueryResults[ 'node' ] );
            $impactfulStoriesNodes = node_load_multiple( $impactfulStoriesNodeIDs );
            $impactfulStories = node_view_multiple( $impactfulStoriesNodes, 'full' );
            print render( $impactfulStories );
          }
        ?>
        <?php // ------ end impactful stories ------ // ?>
 
      </div>
      <div class="col-sm-4">
        <p>Some other content</p>
      </div>
    </div>
  </div>
 
</main>

node--story.tpl.php This is my node--story.tpl.php template.

template.php This is the template.php file for my theme.

Best practices for displaying a taxonomy term, without a link, in a node template in Drupal 7

Just started working with Drupal probably a week ago and I'm struggling to find a place that lists current best practices.

In learning, I've created a custom content type called story and a custom taxonomy called story_category. In story I have a field_term_reference that relates the story_category to story.

Problem: I can render a taxonomy term associated with a node however it automatically renders as a link to the url alias instead of my custom taxonomy field.

Question: What are the current best practice techniques when trying to display a taxonomy term with no link?

My current results: http://imgur.com/um6v459

I appreciate any help. Thanks all!


Here's my setup:

Content Type: Story

Custom Taxonomy: Story Category

page--front.tpl.php

<main>
 
  <div class="container">
    <div class="row">
      <div class="col-sm-8">
 
        <?php // ------ impactful stories ------ // ?>
        <?php
          $impactfulStoriesQuery = new EntityFieldQuery();
 
          $impactfulStoriesQuery
            ->entityCondition( 'entity_type', 'node' )
            ->entityCondition( 'bundle', 'story' )
            ->propertyCondition( 'status', 1 )
            ->fieldCondition( 'field_impactful_story', 'value', 1, '=')
            ->propertyOrderBy( 'created', 'DESC' )
            ->range( 0, 2 );
 
          $impactfulStoriesQueryResults = $impactfulStoriesQuery->execute();
 
          if ( isset( $impactfulStoriesQueryResults[ 'node' ] ) ) {
            $impactfulStoriesNodeIDs = array_keys( $impactfulStoriesQueryResults[ 'node' ] );
            $impactfulStoriesNodes = node_load_multiple( $impactfulStoriesNodeIDs );
            $impactfulStories = node_view_multiple( $impactfulStoriesNodes, 'full' );
            print render( $impactfulStories );
          }
        ?>
        <?php // ------ end impactful stories ------ // ?>
 
      </div>
      <div class="col-sm-4">
        <p>Some other content</p>
      </div>
    </div>
  </div>
 
</main>

node--story.tpl.php

template.php

How do I display a taxonomy term, without a link, in a node template?

In learning, I've created a custom content type called story and a custom taxonomy called story_category. In story I have a term reference for story_category.

I can render a taxonomy term associated with a node however it automatically renders as a link to the URL alias instead of my custom taxonomy field.

How can I display a taxonomy term with no link?

My current result is the following.

screenshot

These are the fields for the Story content up.

These are the fields for the Story Category vocabulary.

This is my page--front.tpl.php template.

<main>
  <div class="container">
    <div class="row">
      <div class="col-sm-8">
        <?php // ------ impactful stories ------ // ?>
        <?php
          $impactfulStoriesQuery = new EntityFieldQuery();
          $impactfulStoriesQuery
            ->entityCondition( 'entity_type', 'node' )
            ->entityCondition( 'bundle', 'story' )
            ->propertyCondition( 'status', 1 )
            ->fieldCondition( 'field_impactful_story', 'value', 1, '=')
            ->propertyOrderBy( 'created', 'DESC' )
            ->range( 0, 2 );
          $impactfulStoriesQueryResults = $impactfulStoriesQuery->execute();
          if ( isset( $impactfulStoriesQueryResults[ 'node' ] ) ) {
            $impactfulStoriesNodeIDs = array_keys( $impactfulStoriesQueryResults[ 'node' ] );
            $impactfulStoriesNodes = node_load_multiple( $impactfulStoriesNodeIDs );
            $impactfulStories = node_view_multiple( $impactfulStoriesNodes, 'full' );
            print render( $impactfulStories );
          }
        ?>
        <?php // ------ end impactful stories ------ // ?>
      </div>
      <div class="col-sm-4">
        <p>Some other content</p>
      </div>
    </div>
  </div>
</main>

This is my node--story.tpl.php template.

This is the template.php file for my theme.

2 edited tags
| link
1
source | link

Best practices for displaying a taxonomy term, without a link, in a node template in Drupal 7

Just started working with Drupal probably a week ago and I'm struggling to find a place that lists current best practices.

In learning, I've created a custom content type called story and a custom taxonomy called story_category. In story I have a field_term_reference that relates the story_category to story.

Problem: I can render a taxonomy term associated with a node however it automatically renders as a link to the url alias instead of my custom taxonomy field.

Question: What are the current best practice techniques when trying to display a taxonomy term with no link?

My current results: http://imgur.com/um6v459

I appreciate any help. Thanks all!


Here's my setup:

Content Type: Story

  1. title
  2. body
  3. field_impactful_story
  4. field_related_fund
  5. field_term_reference
  6. field_summary

Custom Taxonomy: Story Category

  1. name
  2. description
  3. field_story_category_link

page--front.tpl.php

<main>

  <div class="container">
    <div class="row">
      <div class="col-sm-8">

        <?php // ------ impactful stories ------ // ?>
        <?php
          $impactfulStoriesQuery = new EntityFieldQuery();

          $impactfulStoriesQuery
            ->entityCondition( 'entity_type', 'node' )
            ->entityCondition( 'bundle', 'story' )
            ->propertyCondition( 'status', 1 )
            ->fieldCondition( 'field_impactful_story', 'value', 1, '=')
            ->propertyOrderBy( 'created', 'DESC' )
            ->range( 0, 2 );

          $impactfulStoriesQueryResults = $impactfulStoriesQuery->execute();

          if ( isset( $impactfulStoriesQueryResults[ 'node' ] ) ) {
            $impactfulStoriesNodeIDs = array_keys( $impactfulStoriesQueryResults[ 'node' ] );
            $impactfulStoriesNodes = node_load_multiple( $impactfulStoriesNodeIDs );
            $impactfulStories = node_view_multiple( $impactfulStoriesNodes, 'full' );
            print render( $impactfulStories );
          }
        ?>
        <?php // ------ end impactful stories ------ // ?>

      </div>
      <div class="col-sm-4">
        <p>Some other content</p>
      </div>
    </div>
  </div>

</main>

node--story.tpl.php

<article class="story u-clearfix">
  <img class="story-image u-floatLeft" src="http://lorempixel.com/image_output/people-q-c-200-200-4.jpg" alt="">
  <div class="u-floatRight">
    <h3 class="story-title">
      <?php print render( $title ); ?>
    </h3>
    <p class="story-summary">
      <?php if ( $impactfulStorySummary ): ?>
        <?php print render( $impactfulStorySummary ); ?>
      <?php endif; ?>
    </p>
    <div class="story-meta u-clearfix">
      <?php if ( $impactfulStoryCategory ): ?>
        <?php if ( $impactfulStoryCategoryLink ): ?>
          <a class="u-floatLeft" href="<?php print render ( $impactfulStoryCategoryLink ); ?>">
            <?php print render ( $impactfulStoryCategory ); ?>
          </a>
        <?php endif; ?>
      <?php endif; ?>
      <?php if ( $impactfulStoryRelatedFund ): ?>
        <a class="u-floatRight" href="https://www.giveto.osu.edu/makeagift/?fund=<?php print render( $impactfulStoryRelatedFund ); ?>">
          Give
        </a>
      <?php endif; ?>
    </div>
  </div>
</article>

template.php

<?php
  function osu_preprocess_node( &$variables ) {
    // ------ preprocess impactful story nodes ------ //
    if ( $variables[ 'node' ]->type == 'story' ) {

      // get summary for the story content type
      $summaryItem = field_get_items( 'node', $variables[ 'node' ], 'field_summary' );
      $summaryView = field_view_value( 'node', $variables[ 'node' ], 'field_summary', $summaryItem[ 0 ] );
      $variables[ 'impactfulStorySummary' ] = $summaryView;

      // get the taxonomy term associated with a particular story
      $categoryItem = field_get_items( 'node', $variables[ 'node' ], 'field_term_reference' );
      $categoryView = field_view_value( 'node', $variables[ 'node' ], 'field_term_reference', $categoryItem[ 0 ] );
      $variables[ 'impactfulStoryCategory' ] = $categoryView;

      // get the term id so we can get term.
      // once we have the term when can get a field of that term
      $categoryID = $categoryItem[ 0 ][ 'tid' ];
      $category = taxonomy_term_load( $categoryID );

      $categoryLinkItem = field_get_items( 'taxonomy_term', $category, 'field_story_category_link' );
      $categoryLinkView = field_view_value( 'taxonomy_term', $category, 'field_story_category_link', $categoryLinkItem[ 0 ] );
      $variables[ 'impactfulStoryCategoryLink' ] = $categoryLinkView;

      // get the related fund field associated with a story
      $item = field_get_items( 'node', $variables[ 'node' ], 'field_related_fund' );
      $view = field_view_value( 'node', $variables[ 'node' ], 'field_related_fund', $item[ 0 ] );
      $variables[ 'impactfulStoryRelatedFund' ] = $view;
    }
    // ------ end preprocess impactful story nodes ------ //
  }
?>