• Resolved andrewenz

    (@andrewenz)


    Hi.

    Sorry if this is a simple question but I’m new to PHP. I’m trying to add article tags to the bottom of the single template, but it appears get_the_tags() only returns post, not article tags. Does anybody know how I get the article tags?

    	$posttags = get_the_tags();
      	if ($posttags) {
        		$array = [];
        		foreach($posttags as $tag) {
          			$array[] = '<a href="/tag/' . $tag->slug . '/">' . $tag->name . '</a>';
        		}
        		echo "<h2>Tags: </h2><p>" . implode(', ', $array) . "</p><br>";
      	} else {
    		echo "<script>console.log('No tags');</script>";
    	}

    Cheers,
    Andrew.

Viewing 1 replies (of 1 total)
  • Thread Starter andrewenz

    (@andrewenz)

    Never mind. Figured it out. For anybody looking in future, this seems to work. It’s in the content-single.php file under the theme.

    $terms = get_the_terms( $post, 'issuem_issue_tags' );
    $posttags = apply_filters( 'get_the_tags', $terms );
    if ($posttags) {
    	$array = [];
    	foreach($posttags as $tag) {
    		$array[] = '<a href="/article-tags/' . $tag->slug . '/">' . $tag->name . '</a>';
    	}
    	echo "<h2>Tags: </h2><p>" . implode(', ', $array) . "</p><br>";
    } else {
    	echo "<script>console.log('No tags');</script>";
    }
    • This reply was modified 2 years ago by andrewenz.
Viewing 1 replies (of 1 total)
  • The topic ‘Display Article tags’ is closed to new replies.