I have following code in a sidebar of my WP theme: <?php query_posts('category_id=all');?> <?php $posts = get_posts('category=all&offset=0'); foreach ($posts as $post) : start_wp(); ?> <li><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> Code (markup): It only displays 5 latest posts. How do I make it so it displays unlimited posts? Or how do I make it so I can control how many latest posts are displayed? Somebody help, I'm a PHP newb
http://codex.wordpress.org/Template_Tags/get_posts Need to pass in $numberposts to get_posts. The default is .... 5.
Try usiing <?php wp_get_archives('type=postbypost&limit=10'); ?> Instead of <?php $posts = get_posts('category=all&offset=0');
Thanks guys, MegaMania: tried that - it worked but also included the name of a blog hyperlinked to the homepage at the bottom of the list shallowink: great link, I may have fixed my problem with advice given there. This is what the code looks like and it seems to work: <?php $lastposts = get_posts('numberposts=20'); foreach($lastposts as $post) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> Code (markup): Thanks again guys, green rep on the way for both of you
I need help one more time (I'm totally worthless with PHP and didn't want to start a separate thread) I'm trying to display random posts with hyperlinked title and excerpt of content. This is the code I could come up with but while hyperlinked titles are shown, no except is displayed. What am I doing wrong? <?php $rand_posts = get_posts('numberposts=5&orderby=rand'); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <div class="entry"> <?php the_excerpt() ?> </div> <?php endforeach; ?> Code (markup):
think get_posts isn't accessing all of the post data. from the same link I sent earlier... <?php $lastposts = get_posts('numberposts=3'); foreach($lastposts as $post) : setup_postdata($post); ?> setup_postdata is the addition , aint sure its the answer but good place to start...