• Resolved bekabug

    (@bekabug)


    I am trying to get the category ID printed into an area of my category.php file.

    I don’t really know what I am doing so I have pieced together this from the codex, so far…

    <?php if( is_category(32) || is_category(35)) { ?>
    <!-- this actually prints the category onto my page, score, now i need it into the get_posts -->
        <?php
    foreach((get_posts()) as $category) {
        echo $category->cat_ID . ' ';
    }
    ?>
    
     <ul>
     	<?php
     	global $post;
     	$myposts = get_posts('category=32');
     	foreach($myposts as $post) :
     	?>
      		<li><a href="<?php the_permalink(); ?>/"><?php the_title(); ?></a></li>
    
    	<?php endforeach; ?>
     </ul>  	
    
    <?php } ?>

    I would like this statement to be able to get the category ID and put it in the get_posts argument. Where do I go from here?

Viewing 1 replies (of 1 total)
  • Thread Starter bekabug

    (@bekabug)

    Ok the fact that one one helped me here was a little disappointing.

    I finally got some help elsewhere.

    <?php if( is_category(32) || is_category(33) || is_category(35) || is_category(34) || is_category(28) || is_category(29) || is_category(32) || is_category(30) || is_category(31) || is_category(36) || is_category(37) || is_category(38) || is_category(39)) { ?>
    
    <?php
    foreach((get_the_category()) as $category) { 
    
    $theCategory = $category->cat_ID . '';
    
    }
    ?>
    <ul>
     	<?php
     	global $post;
     	$myposts = get_posts('numberposts=1000&order=ASC&orderby=post_title&category=' . $theCategory);
     	foreach($myposts as $post) :
     	?>
      		<li><a href="<?php the_permalink(); ?>/" ><?php the_title(); ?></a></li>
    
    	<?php endforeach; ?>
     </ul>  
    
    <?php } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Unsure about conditional query’ is closed to new replies.