Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

How to Link to category titles if it is in the single post content?

$
0
0

Replies: 0

I want to link to titles of child-categories that are in the single post content.

Example:

My Categories:

Aplle , Asia , Europ , North america , …

My Post Content:

An apple is a sweet, edible fruit produced by an apple tree (Malus domestica). Apple trees are cultivated worldwide and are the most widely grown species in the genus Malus. The tree originated in Central Asia, where its wild ancestor, Malus sieversii, is still found today. Apples have been grown for thousands of years in Asia and Europe and were brought to North America by European colonists. Apples have religious and mythological significance in many cultures, including Norse, Greek and European Christian tradition.

and, My troubled PHP script for automatic create Link to category titles if it is in the single post content:

<?php
   $term_id = 1209;
   $taxonomy_name = 'category';
   $termchildren = get_term_children( $term_id, $taxonomy_name );
   foreach ( $termchildren as $child ) {
      $term = get_term_by( 'id', $child, $taxonomy_name );
      $mycatone = "'" . $term->name . "',";
      $mycattwo = '"' . "<a href='This-Category-URL-LINK'>" . $termd->name . "</a>" . '",';
   }
   function link_words($content){
      $words = array( $mycatone );
      $links = array( $mycattwo );
      $content = str_replace($words , $links ,$content);
      return $content;
   }
   add_filter('the_content', 'link_words');
?>

<?php the_content() ?>
  • This topic was modified 24 minutes ago by ramoures.

Viewing all articles
Browse latest Browse all 59525

Trending Articles