WordPress.org

Ready to get started?Download WordPress

Forums

Show Asides in all Categories (6 posts)

  1. dl33
    Member
    Posted 8 years ago #

    Hi all,
    I put my asides in the sidebar. However, they are only showing up in the category that they are in. How can I make them show no matter what category they are in? (I could put them in all categories, but that would mess up my post count for the normal categories..)
    Help?
    dl33

  2. Kafkaesqui

    Posted 8 years ago #

    "I put my asides in the sidebar."

    There's about a half-dozen ways to implement Asides in WordPress. It would help to know which method you're using.

    "How can I make them show no matter what category they are in?"

    Displayed on say a sidebar, or commingled with the category's posts?

  3. dl33
    Member
    Posted 8 years ago #

    "I put my asides in the sidebar."
    I used the way described in http://codex.wordpress.org/Adding_Asides#Displaying_Asides_on_the_Sidebar
    Should I use another more convienient way?
    I want all asides (the most recent ones) to show on the sidebar, no matter what page you are on. (All pages that load sidebar.php should show the asides.)
    dl33

  4. Kafkaesqui

    Posted 8 years ago #

    Sorry, missed you mentioning its use on the sidebar. Anyway, here's Asides on the sidebar all the time (uses get_posts()):

    <?php
    $asides = get_posts('category=14');
    if($asides) : foreach($asides as $post) : setup_postdata($post);
    ?>
    <div class="asides_sidebar">
    <p><?php echo wptexturize($post->post_content); ?>
    <small><?php comments_popup_link(__('[0]'), __('[1]'), __('[%]')); ?><?php edit_post_link('Edit', ' — '); ?></small></p>
    </div>
    <?php endforeach; else: ?>
    <div class="asides_sidebar">
    <p>Sorry, no Asides.</p>
    </div>
    <?php endif; ?>

    Alter the 'category' value in get_posts() to your Asides category ID. If you'd like to specify the number of "asides" to display, add a 'numberposts' parameter to get_posts():

    $asides = get_posts('category=14&numberposts=10');

    get_posts() should display 5 by default. Finally, you can change:

    <?php echo wptexturize($post->post_content); ?>

    to:

    <?php echo the_content(); ?>

    if you prefer the normal output, but by passing post content only through wptexturize() (to apply the fancy text formatting) we can keep everything, post text and comment link, on one line.

  5. dl33
    Member
    Posted 8 years ago #

    Sweet, this works....
    I am assuming that I keep all the other code the same (in index.php and in the sidebar.php)? The link that I posted before also told me to insert other code... That stays the way it is, right? Or does it not have any function anymore?

    Oh, and one more question:
    Since I inserted the code (look in the link) into my loop, it will not display the content of the aside in my main content anymore. (Which is good.) However, I do want it to show if I am on a single page: I have this code in my loop now:

    <?php rewind_posts(); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( !(in_category('6')) ) { ?>
    THE LOOP
    <?php } ?>
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    How do I have to change the line <?php if ( !(in_category('6')) ) { ?> so that the loop is not executed for all asides, except when the page is a single page? (Sorry, wordpress newbie)
    Thanks a looot already, dl33

  6. dl33
    Member
    Posted 8 years ago #

    (Just replying to get this post back to the top) Can anyone have a loo at the post before this... I tried quite a few things, but that only messes up everything: (Nothing will show anymore...)
    Thanks,
    dl33

Topic Closed

This topic has been closed to new replies.

About this Topic