Passing a PHP variable through a WordPress Tag

Discussion in 'PHP' started by jami0821, Jul 18, 2010.

  1. #1
    I'm relatively new to PHP so please forgive if this is a newb question...

    I'm trying to use the WP_Query class to display a specific category blog post. I have it hooked into a theme admin panel where the user chooses which category posts he/she wants to display.

    My problem is I don't know how to display that chosen category name correctly inside WP_Query.

    Here is what I have so far:

    
    <?php 
    			$category1 = get_option('uf_first_feat_cat');
    			$recent = new WP_Query('cat='.$category1.'&showposts=1'); while($recent->have_posts()) : $recent->the_post();?>
    				<div <?php post_class() ?> id="post-<?php the_ID(); ?>">								
    						<p class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_titlesmall('', '...', true, '25') ?></a></p>
    				<!-- POST CONTENT -->
    				<div class="post_content">		
    					<?php $thumbnail = get_post_meta($post->ID, "Thumbnail", $single = true); ?>
    						<img id="cat-thumb-left" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $thumbnail; ?>&#38;h=120&#38;w=275&#38;zc=1" align="left" alt="" />
    						<!-- POST META -->				
    						<p class="home-post-details">Posted in <?php the_category(', ') ?> on <?php the_time('m/d/y') ?></a></p>	
    						<?php the_excerpt(); ?><span class="readmore"><a href="<?php the_permalink(); ?>">Read More</a></span>
    				</div> <!-- end #post_content -->	
    			<?php endwhile; ?>
    				</div> <!-- end #post-cat# -->
    
    PHP:
    ...where $category1 is the chosen category by the user. Now how to do define that variable in the second line with WP_Query?

    This is what I tried so far and it doesn't work. Anyone know what I'm doing wrong here?

    
    WP_Query('cat='.$category1.'&showposts=1');
    
    PHP:

     
    jami0821, Jul 18, 2010 IP
  2. jami0821

    jami0821 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've solved my own problem. It had nothing to do with formatting incorrectly.

    I needed to use 'category_name' instead of 'cat' in the WP_Query $args. Otherwise it was calling the category NUMBER instead of the category NAME (which is what I wanted).
     
    jami0821, Jul 18, 2010 IP