Forums

Popular Post by category without coding cat ID? (3 posts)

  1. woodenpier
    Member
    Posted 1 year ago #

    Hi all, I'm working on a new theme to release to the public and I am trying to make it as easy as possible for non-tech folks to configure (without me having to develop a whole options interface plugin).

    So i have a section that shows the most popular post (based on number of comments) only 1 post by category. Currently I am using the query each time and changing the category ID... but I'd rather make it so that the end user doesn't have to go in and change the ID in the code.

    I've been trying to think of a way to have an extra category called Popular that the user can choose and then query based on the name 'Popular' AND number of comments... but I want each 'post shown to be from a different category (it's a magazine style theme with space for three posts horizontally and I don't want them to all be from the same category) Ideally the client would choose the three categories by ALSO marking them with the category 'Popular'... but how do I write the PHP so that it will return 3 posts, each from the category Popular, AND making sure that they are NOT duplicates of the 'other' more semantically correct category?

    I know this looks like an essay! But I didn't know how better to explain it.

    Currently my 'block' per post looks like this... I just change the category ID and add another block manually.

    <div class="popular-block">
         <?php
              $month = date('m');
              $year = date('Y');
              query_posts('post_type=post&showposts=1&cat=4orderby=comment_count&order=DESC&year=' . $year .'&monthnum=' . $month);
    
              while (have_posts()): the_post(); ?>
    
              <a class="pop_cat_title" href="<?php echo get_category_link(4);?>"><?php echo get_cat_name(4);?></a>
    
              <a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=182&h=100&zc=1&q=100" alt="<?php the_title(); ?>" class="left" width="182px" height="100px"/></a>
    
              <span class="pop_comments"><?php comments_popup_link('0', '1', '%');?></span>
              <a class="pop_post_title" href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a>
    
        <?php
    
        endwhile;
        wp_reset_query();
        ?>
    </div><!-- .popular_block -->
  2. woodenpier
    Member
    Posted 1 year ago #

  3. woodenpier
    Member
    Posted 1 year ago #

    Really? No comments?

    I've been reading these posts for years and thought someone would enjoy this kind of though process challenge. I'm a UI designer (who's developer is away) and my brain doesn't think in if/else... but I think it's amazing that some people do!

Topic Closed

This topic has been closed to new replies.

About this Topic