Forums

Help with a code (3 posts)

  1. lalng001
    Member
    Posted 2 years ago #

    Is there anyway that i can get the category where the post is posted automatically?

    I now of a code that can get a category but i must give the category of where it will get posts.

    <?php
    
    		$the_query = new WP_Query('category_name='. XXXXX . '&' . 'showposts='. XXX);
    
    		while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID;
    ?>

    I plan to put it in my single.php file, so i need it to automatically get the category of where the post is posted and show the other post on the category.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

  3. lalng001
    Member
    Posted 2 years ago #

    ok thanks for the reply, but will this code get the category of where my post is posted?

    <?php
    global $post;
    $categories = get_the_category($post->ID);
    var_dump($categories);
    ?>

    And how should i get the other post in the category?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.