WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Unsure about conditional query (2 posts)

  1. bekabug
    Member
    Posted 6 years ago #

    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?

  2. bekabug
    Member
    Posted 6 years ago #

    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 } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.