• Well folks, the business is next. I am creating a widget to the sidebar. This widget has to recognize which category it is in the moment, and from there select the subcategory with the name columnists and display 5 posts in this subcategory.

    Hierarchy of the Journal online

    2013 -> 175 Edition -> Columnists (posts that are in category columnist)

    My code is looking for the SLUG and not the category name.
    The problem is that the slug change according to their parent categories (EX: clunista-edicao175) so I can not use it.

    <?php
    $category = get_the_category();
    $catParID = $category[0]->category_parent;
    $catParent = get_cat_name($catParID);
    
    $myquery = new WP_Query('cat='.$catParID.'&category_name=colunistas&posts_per_page=5' );
    
    if ($myquery->have_posts()) : while ($myquery->have_posts()) : $myquery->the_post(); ?>
    
    <aaa hreeeeeef="<?php the_permaliiiiink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?>
    
    <?php endwhile; endif;
    
    wp_reset_query(); ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

  • The topic ‘Return to post a specific category.’ is closed to new replies.