Support » Themes and Templates » can I display a "tag" wihout linking to archive.php

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator stephencottontail

    (@stephencottontail)

    I think the closest function to what you’re looking for is get_the_tags(), which returns an array of objects. You would then have to iterate over the array to get the appropriate information:

    <?php
    $post_tags = get_the_tags();
    
    if ( $post_tags ) {
      foreach ( $post_tags as $tag ) {
        echo $tag->name . ' ';
      }
    }
    ?>

    Hi Stephen,
    Worked perfectly.

    For anyone who may stumble upon this post here is my query that you can use as a sample or starting point.

    <?php
    // The Query : Set limiter in WP_Query below
    
    $the_query = new WP_Query('tag=commencement-highlights');
    
    	echo '<ul class="small-block-grid-1 large-block-grid-1">';
    
    // The Loop
    
    while ( $the_query->have_posts() ) {
    
    	$the_query->the_post();
    
    	echo '<li><div class="panel"><a href="' . get_permalink() . '">';
    
    			if ( has_post_thumbnail() ) {
    
    			the_post_thumbnail('full');
    
    			echo '</a>';
    
    				$posttags = get_the_tags();
    				if ($posttags) {
    				  foreach($posttags as $tag) {
    				    echo '<div class="flag" style="background-image:url(' . $flag['url'] . ');">'; // $flag is an image url
    				    echo $tag-> name ;
    				    echo '</div>';
    				  }
    				}
    
    		}
    
    		else {
    
    			// do nothing
    
    		}
    
    	echo '<a href="' . get_permalink() . '"><h1>' . get_the_title() . '</a></h1>';
    
    	echo '<p>' . get_the_excerpt() . '<p></a></div></li>';
    
    }
    
    	echo '</ul>';
    
    wp_reset_postdata();
    ?>

    Here is a visual representation of the results
    Click for image

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘can I display a "tag" wihout linking to archive.php’ is closed to new replies.