• Hello,

    I’m using the following code to show the post titles of the current category.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		<ul>
    			<?php
    
    			$catsy = get_the_category();
    		    $myCat = $catsy[0]->cat_ID;
    			$IDOutsideLoop = $post->ID;
    			global $post;
    			$myposts = get_posts('category='.$myCat);
    			foreach($myposts as $post) :
    			?>
    
    			<li <?php if($IDOutsideLoop == $post->ID) print 'class="current-cat"' ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    			<?php endforeach; ?>

    But for some strange reason it just shows the last five.
    Anybody has an idea why?

    Thanks, Ka

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try $myposts = get_posts('category='.$myCat . '&posts_per_page=10');

    Thread Starter esferapublica

    (@esferapublica)

    thanks esmi,
    but unfortunately doesn’t work. strange ??

    Thread Starter esferapublica

    (@esferapublica)

    Nobody?

    Thread Starter esferapublica

    (@esferapublica)

    I don’t get it.
    I got the code from another post in the forum. I know it’s bad copying and using code without understanding it. But it looks quite simple.
    It makes no sense why it doesn’t work.

    I tried this from another poster – worked, but still just showed the last five.

    Strange.

    Thread Starter esferapublica

    (@esferapublica)

    ok, I used this and it weirdly worked.

    <?php if(is_category() || is_single()){
     global $post;
     foreach(get_the_category() as $category)
     {
      $current = $category->cat_ID;
      $current_name = $category->cat_name;
     }
    }
    echo $current_name . " has id ".$current;
    $myposts = get_posts('numberposts=50&category='.$current);
    foreach($myposts as $post) : ?>
           <li>
             <a href="<?php the_permalink(); ?>">
             <?php the_title(); ?></a>
           </li>
    <?php endforeach; ?>

    maybe still somebody has a clue, why the first didn’t work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post titles of current category, shows just first five’ is closed to new replies.