• Resolved guzh

    (@guzh)


    Hi!
    I read this post about this matter in a single list, and it works fine. But I was wondering how it’s possible to make several post-lists with the highlight-function.

    the code to highlight the title of the post showing on the single-post-page:

    <ul class="sidebar-ul">
    <?php
    
    $IDOutsideLoop = $post->ID;
    global $post;
    
    $myposts = get_posts('showposts=5');
    foreach($myposts as $post) :
    ?>
    
    <li <?php
    if(is_single() && $IDOutsideLoop == $post->ID) 
    
    {
    echo " class=\"current\"";
    }
    ?>>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
    <?php endforeach; ?>
    
    </ul>

    I use this code to show multiple lists:

    // FIRST LOOP: display posts 1 thru 5
    <?php query_posts('showposts=5'); ?>
    <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
    
    <?php the_title(); ?>
    <?php the_content(); ?>
    
    <?php $count1++; } ?>
    <?php endforeach; ?>
    
    // SECOND LOOP: display posts 6 thru 10
    <?php query_posts('showposts=5'); ?>
    <?php $posts = get_posts('numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?>
    
    <?php the_title(); ?>
    <?php the_content(); ?>
    
    <?php $count2++; } ?>
    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Little confused by the 2 differing pieces of code you posted, but here’s a refined version of the second chunk, adjust the code as required.

    <?php
    $poststoshow = 5;
    if(is_single()) { $currentpost = get_the_ID(); }
    
    $posts = get_posts('numberposts='.$poststoshow); ?>
    <ul>
    <?php
    foreach ($posts as $post) { 
    
    	setup_postdata($post);
    	static $count1 = 0; 
    
    	if ($count1 == "5") {
    		break;
    	}
    	else { ?>
    		<li<?php if($currentpost == $post->ID) { echo ' class="current"'; } ?>><?php the_title();?></li>
    		<?php
    		//the_content();
    		$count1++;
    	}
    } ?>
    </ul>
    <?php
    unset($posts);
    $posts = get_posts('numberposts='.$poststoshow.'&offset='.$count1);
    ?>
    <ul>
    <?php
    foreach ($posts as $post) {
    
    	setup_postdata($post);
    	static $count2 = 0;
    	if ($count2 == "5") {
    		break;
    	}
    	else { ?>
    		<li<?php if($currentpost == $post->ID) { echo ' class="current"'; } ?>><?php the_title();?></li>
    		<?php
    		//the_content();
    		$count2++;
    	}
    }
    ?>
    </ul>
    Thread Starter guzh

    (@guzh)

    ah, thank you! ;D
    just as I wanted!

    (I just copied the second code directly from a page, and didn’t edit it to be a list. Sorry for the inconvenience!)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to highlight current post title in multiply lists’ is closed to new replies.