• Resolved deeltje

    (@deeltje)


    The code I’m using right now is displaying the 6 newest posts, but I’d like to have it auto-detect the category the post is in, so in single.php and category.php the code would display the posts in that specific category.

    Can someone help me with this?

    <?php $my_query = new WP_Query('showposts=6');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    <div id="contentslider_menu"><div class="contentslider_menubalk_streep"><div class="contentslider_menubalk"><ul><li><a href="<?php the_permalink(); ?>" class="toc">
    
    <p class="wit"><?php the_title(); ?></p>
    </a></li></ul></div></div></div>
    <?php endwhile; ?>
Viewing 7 replies - 16 through 22 (of 22 total)
  • come to think of it, aren’t you putting that code in single.php?

    Related:
    Template Hierarchy

    Thread Starter deeltje

    (@deeltje)

    No I’m putting the code in header.php, which worked so far, the only thing that didn’t work was the category detection on single.php.

    The reason I started this post was because I wanted to use minimalized code, sure I could easely put the code in index.php/category.php and single.php instead, but if it’s possible not to, then that would be just a whole bunch greater ??

    Or isn’t this possible because single is in a different hierachy then category.php? And is that the reason why index.php would just take all the new posts also?

    Thread Starter deeltje

    (@deeltje)

    And again, here I go ??

    How do I display posts per specific user ?

    something with the_author ?

    (The user is a subscriber)

    To present links to an author’s posts:
    1. Use the template tag, wp_list_authors(), in your sidebar or a Widget.
    2. or, use template tag, the_author_posts_link(), in your loop.

    To customize and author template read Author Templates

    Thread Starter deeltje

    (@deeltje)

    Yeah I know links to authors_posts, but I want to show the posts of specific authors.

    Use the template tag, query_posts(), and the author= argument.

    Thread Starter deeltje

    (@deeltje)

    <?php
    if ( is_page() ) {
    $cats = wp_get_post_categories($author->ID);
    $args=array(
       'cat' => $cats[0],
       'showposts'=> 6,
       'author_name' => 'Specific_Username'
       );
    }
    $my_query = new WP_Query($args);
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    ?>

    I’m beginning to understand this ??

    @michaelh,

    Thanks a LOT for all your help!

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Auto-detect Category’ is closed to new replies.