Forums

[resolved] Post by author exclude categories (6 posts)

  1. hbalagh
    Member
    Posted 2 years ago #

    I haven't been getting very much support here these days so i'm not even sure this request will be answered but i will try anyhow.

    If you go to

    http://www.bpdfriends.com/blog/self-help-blog/2009/11/how-to-not-take-things-personally/

    i want to have a list of recent post in the sidebar of the author who wrote that particular post but to exclude certain categories...

  2. stvwlf
    Member
    Posted 2 years ago #

    hi

    I can't guarantee the author-category combination will work since I haven't tried it, but if it works it will look like this -

    query_posts('author=1&cat=-3,-6');

    where author=1 is the author id of the author, and cat=-3,-6 means exclude posts that are in those two category ID's. a minus # on categories always means exclude.

    I suggest making a custom loop and putting it in the sidebar - this shows up to 5 posts. Note that if a post is in two categories and one is excluded and the other isn't, the post will not be excluded.

    <h3>Recent Posts</h3>
        <ul>
        <?php
            $recentPosts = new WP_Query();
            $recentPosts->query('author=1&cat=-3,-6&posts_per_page=5');
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
        </ul>
  3. hbalagh
    Member
    Posted 2 years ago #

    i need it to show post from that particular author not just the admin's so if im viewing a post by the name of adam it will show on the sidebar the last 5 post made from him or if im viewing post from susan it will show the last 5 of hers.. and so on

  4. stvwlf
    Member
    Posted 2 years ago #

    Then try this. You must have double quotes on the query statement.

    <?php $authorID = get_the_author_meta('ID'); ?>
    <h3>Recent Posts</h3>
        <ul>
        <?php
            $recentPosts = new WP_Query();
            $recentPosts->query("author=$authorID&cat=-3,-6&posts_per_page=5");
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
        </ul>
  5. hbalagh
    Member
    Posted 2 years ago #

    thanks works great...now any clue of how to make it so it says recent post by authors name?

  6. hbalagh
    Member
    Posted 2 years ago #

    nevermind i really dont need it

Topic Closed

This topic has been closed to new replies.

About this Topic