WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is it possible to exclude categories using wp_get_archives ? (16 posts)

  1. gerld
    Member
    Posted 7 years ago #

    i'm trying to add a sidebar which will only have category "3" displaying.

    can i use wp_get_archives to limite the display to category 3 ?

    i also tried using query_posts cat='3' but that also affects my main content for some reason. is there a way that i can use more than one query_post on a page ?

    please help

  2. gerld
    Member
    Posted 7 years ago #

    i managed to exclude category 3 on my main content, and INcluded it in the sidebar,

    however, now whenever i click on a single article... i see all of them instead of the individual article (i tried adding the same query_posts exclude to the single.php page, but it still shows all articles .. except category 3 obviously)

    i have no idea why this is. any ideas?

  3. gerld
    Member
    Posted 7 years ago #

    i've pretty much read through every single post with an exclude tag.. and i don't understand why this is so difficult.

    there surely has to be a simple way to do this

  4. Kafkaesqui

    Posted 7 years ago #

    Try using get_posts():

    http://codex.wordpress.org/Template_Tags/get_posts

    It offers a category parameter you can use to limit to one category. It also avoids the headaches query_posts() can cause when it's implemented for something beyond the default query.

  5. gerld
    Member
    Posted 7 years ago #

    i tried getposts but it doesn't seem to work in wp 2

  6. Kafkaesqui

    Posted 7 years ago #

    Did you try getposts() or get_posts()? The latter is the correct function name, and it works fine in WP2.

  7. gerld
    Member
    Posted 7 years ago #

    i tried the exact code listed on codex

    <?php
    $myposts = get_posts('numberposts=5&offset=1&category=3');
    foreach($myposts as $post) :
    ?>
    <?php the_content(); ?>
    <?php endforeach; ?>

    it just outputs a blank page

  8. Kafkaesqui

    Posted 7 years ago #

    How about:

    <?php
    $myposts = get_posts('numberposts=5&offset=1&category=3');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    <?php the_content(); ?>
    <?php endforeach; ?>

  9. gerld
    Member
    Posted 7 years ago #

    awesome that works. thanks so much!

  10. djen
    Member
    Posted 7 years ago #

    I'm trying to do a similar thing, but with no success. I put the code provided by Kafkaesqui in my sidebar.php, and it gets the entire post instead of just the post title. How do I get it to just show the title of the post?

    Am I missing something?

  11. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    djen: Try using the_title() instead of the_content().

  12. djen
    Member
    Posted 7 years ago #

    Thanks for the quick response. That definitely pulls in the titles of the posts, but it runs them all together into one big paragraph, and none of them are showing up as links to the original posts.

    How do I make it link to the posts and put space between the titles?

    Thanks again!

  13. djen
    Member
    Posted 7 years ago #

    I put spaces between the titles by doing this:

    <?php the_title(' ','<p>'); ?>

    But still no links.

  14. djen
    Member
    Posted 7 years ago #

    Here's what I have:

    <?php
    $myposts = get_posts('numberposts=5&offset=1&category=3');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    <?php the_title(' ','<p>'); ?>
    <?php endforeach; ?>

    It puts up the title of the post, but the title doesn't link to anything.

  15. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Try this instead of your call to the_title():
    <p><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>

  16. djen
    Member
    Posted 7 years ago #

    Hey, that works! Thanks a million Otto42, you're a champ!

Topic Closed

This topic has been closed to new replies.

About this Topic