WordPress.org

Ready to get started?Download WordPress

Forums

Category Specific Menu (4 posts)

  1. sithicus
    Member
    Posted 8 years ago #

    Ok,

    What i would like to do is create a menu on my category pages are regular category pages, that figures out what the current category is and display the posts under that category.

    ex// If i have 10 caetgories and the user clicks on the design category, when they are on the design category page I would like to display a menu that shows the other posts that are under the design category.

    I've searched and search on this and I just can't seem to figure out of if this is possible, I know if the design category was a specific page there would be lots of ways to do this because I could set a template tag or a plugin to display a specific category id, but since it is dynamic is there a way to store the category id in a variable and then drop that variable into.. something like this:

    <?php
    $posts = get_posts('numberposts=10&order=ASC&orderby=date&category="%categoryidvariable%"');
    foreach ($posts as $post) : start_wp(); ?>
    <?php the_title(); ?>
    <?php endforeach; ?>

    I think this would make it dynamice depending on the page.. I'm not a php expert and I'm not sure how to store the category id in a variable... or if this is even possible.. any thoughts??

  2. sithicus
    Member
    Posted 8 years ago #

    I am now thinking I need to somehow drop...

    <?php
    $posts = get_posts('numberposts=5&category="<?php echo $catID ?>"');
    foreach ($posts as $post) : start_wp(); ?>
    <?php the_title(); ?>
    <?php endforeach; ?>

    because the catID shoudl automatically be set to the current category.. when inside that category..?

  3. moshu
    Member
    Posted 8 years ago #

    I guess nobody really cares about a solution because if you are NOT a beginner blogger then you might have 277 posts in that category... and displaying all of them in the sidebar is a nonsense.
    Just my $0.02

  4. sithicus
    Member
    Posted 8 years ago #

    This is the proper way to do this MADDDDD propts to alphaoide.

    <?php
    $cat = get_the_category();
    $cat = $cat[0];
    $posts = get_posts("category=" . $cat->cat_ID . "&numberposts=5");
    if( $posts ) :
    ?>
    <div class="recent-posts">
    <h2>More on this category</h2>

    </div>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic