Latest Posts in a drop down menu
-
I am trying to do something that is on the very edge (arguably just beyond) my technical ability. I built the theme for my wife’s real estate page. It features a bottom portion that list the latest posts in a couple of categories (news and blog). I have been playing with adding a drop down menu at the top of the page. What I would like is for you to mouse over “news” and have a drop down menu of the last 5 posts, and a 6th option of “MORE…” which would take you to page 2 of the news archive. I would like the same for the “blog” menu item.
I have gotten this to work utilizing the same code as I used in the bottom portion of the page. However, it displays the latest post in every post, page, and archive on the site. Clearly, this is some kind of loop problem. I have tried the “rewind post” solution with no luck.
Here is the code I am using to display the post titles at the bottom of the page. Ignore the extra code getting the time, this just displays a “new” tag if it is less than a week old.
<?php $posts = get_posts('category=1&numberposts=4'); foreach($posts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php // get the time of the current post $u_time = get_the_time('U'); // reset my selector $tooOld = 0; // set the time selector if ( ( time('U') - 432000 ) >= $u_time ) { $tooOld = 1; } // 60*60*24*7 = 604800 = 7 days ?> <?php if($tooOld < 1 ) { ?> <span class="new"><strong>NEW</strong></span> <?php } ?> </a></li> <?php endforeach; ?>
So essentially I am trying to use this code twice in the same page, once in the header as a drop down menu, and once in the footer where it exists peacefully now. Extra gold star for anyone who can help me figure this out.
- The topic ‘Latest Posts in a drop down menu’ is closed to new replies.