1

What i want To Do is to show Related Articles via Categories

For example I have a Movie Named " ABC " in Category Named HDTV , and this movie is Also added in other Categories Via the Same Title .

And Here Is an image that shows the case.

enter image description here

Thank You in Advance.

8
  • you need to use category Dec 17 '16 at 12:23
  • what do you mean by that ? cause im already using categories .
    – Marwisso
    Dec 17 '16 at 12:24
  • okay can you please place your single.php Dec 17 '16 at 12:25
  • here is it : paste2.org/46bHjGOa
    – Marwisso
    Dec 17 '16 at 12:27
  • its block I can't open Dec 17 '16 at 12:27
1

First you have to create secondary loop and use it.

//     $categories = wp_get_post_categories($post->ID);
     $categories = get_the_category($post->ID);
     foreach ( $categories as $category ) { 
       echo $category->name;
     }

Description

get_the_category( $post->ID );

This tag may be used outside The Loop by passing a post id as the parameter.

Note: This function only returns results from the default “category” taxonomy. For custom taxonomies use get_the_terms().

10
  • thanks but i think You didnt understand me , i dnt want to show other posts , i want to show the category name and when u click on any of theme it does take you directly to the article in that category .
    – Marwisso
    Dec 17 '16 at 12:34
  • ok wait a second i ll try it
    – Marwisso
    Dec 17 '16 at 12:38
  • soory it didnt work for me , <?php $categories = get_the_category(); $tags = get_the_tags(); $post_id = get_the_ID(); $categories = get_post_categories( $post_id ); ?>
    – Marwisso
    Dec 17 '16 at 12:42
  • <?php $categories = get_the_category(); $tags = get_the_tags(); $post_id = get_the_ID(); $categories = get_post_categories( $post_id ); ?>
    – Marwisso
    Dec 17 '16 at 12:43
  • it shows that error : Array ( [0] => 90 [1] => 15 )
    – Marwisso
    Dec 17 '16 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.