• Resolved vestaviascott

    (@vestaviascott)


    I’ve got the code to list all recent posts, but I want to first check to see if the list is >= 10 and if so, I want to include a link to a page that will list all posts on a separate page which I can create easy enough.

    I just need help with the code to count the number of posts and either show or not show the “View All Posts” link.

    In the code below, I’m looking for all posts that are (a) Not sticky and (b) Not in the “top-menu” category…

    I just need to mod this script to do what I describe above

    <ul><h2 class="widgettitle">Recent Posts</h2>
    			<?php
    			global $post;
    			$cat=get_cat_ID('top-menu');
    			$myposts2=get_posts(array('post__not_in'=>get_option('sticky_posts'),'cat'=>-$cat));
    			foreach($myposts2 as $post) :
    			?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    			<?php endforeach; ?>
    		</ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Note the added showposts=10 to the query…

    <ul><h2 class="widgettitle">Recent Posts</h2>
    			<?php
    			global $post;
    			$cat=get_cat_ID('top-menu');
    			$count=0;
    			$myposts2=get_posts(array('post__not_in'=>get_option('sticky_posts'),'cat'=>-$cat,'showposts'=>10));
    			foreach($myposts2 as $post) :
    			$count++; ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    			<?php endforeach;
    			if ($count >=10) {
    			echo '<a href="https://yourdomain.com/yourpage">See more details here</a>';
    			}
    			?>
    		</ul>

    Thread Starter vestaviascott

    (@vestaviascott)

    Michael, you continue to amaze me. Huge Props!

    ~ s

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List 10 most recent posts, then a “View All Posts” link. Code help’ is closed to new replies.