MartinNeumann Posted May 25, 2010 Share Posted May 25, 2010 Hi there - I hope someone can help, cause I've been pulling my hair out for hours. Here's what I want to do: On my Index page of my blog I want the latest post to appear in full. Then below it I want to have a list of all the recent posts (titles only) - so when I add a new post the current one moves to the list and so on. Here's the code in question - I'm not sure if I'm allowed to link to my site so you can see what it's doing but it's repeating itself over and over. <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <div class="article" id="<?php the_ID(); ?>"> <span class="postmeta"><?php the_time('F jS, Y') ?></span> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_content('Read the rest of this entry »'); ?> <?php endwhile; ?> <br /><br /> <!-- Do other stuff... --> <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> <span class="postmeta"><?php the_time('F jS, Y') ?></span> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php endwhile; endif; ?> If anybody can help that'll be awesome and it'll make my day. Cheers, Martin Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/ Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 I see no reason why you cannot link to your site. What's repeating over and over, the full article? Also, is that the full file, as I'm receiving an unexpected end of file error. I've also neated it up a bit: <?php if (have_posts()) : while (have_posts()) : the_post(); $my_query = new WP_Query('category_name=featured&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; echo '<div class="article" id="<?php the_ID(); ?>"> <span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; the_content('Read the rest of this entry »'); endwhile; echo '<br /><br />'; if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); echo '<span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; endwhile; endif; ?> Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/#findComment-1063019 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 <?php if (have_posts()) : while (have_posts()) : the_post(); $my_query = new WP_Query('category_name=featured&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; echo '<div class="article" id="<?php the_ID(); ?>"> <span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; the_content('Read the rest of this entry »'); endwhile; endwhile; endif; echo '<br /><br />'; if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) : continue; update_post_caches($posts); echo '<span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; endif; endwhile; endif; ?> Try that. Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/#findComment-1063026 Share on other sites More sharing options...
MartinNeumann Posted May 25, 2010 Author Share Posted May 25, 2010 Thanks Karl, The site is at http://smallofficeoz.com Also, I thought that I'd put in the php code that's affected. BTW, I tried your changes and it came up with: Parse error: syntax error, unexpected T_ENDWHILE Following is the full Index page: <?php define('WP_USE_THEMES', false); get_header(); ?> <body> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-91947-27']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <div align="center"> <br> <table border="0" cellpadding="0" cellspacing="0" width="800"> <tbody> <tr> <td> <img src="http://theebookagency.com/images/top_bar.gif" name="small office australia" alt="home office australia"></td> </tr> </tbody> </table> <table style="width: 800px; height: 84px;" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td background="http://theebookagency.com/images/left_side.gif" width="39"></td> <td valign="top"> <a href="http://www.smallofficeoz.com/"><img src="http://smallofficeoz.com/images/SmallOfficeOz-logo.png" border="0" /></a> </td> <td> <div class="nav"> <a href="http://www.smallofficeoz.com/">home</a> <a href="http://www.smallofficeoz.com/premium/">premium</a> <a href="http://www.smallofficeoz.com/resources/">resources</a> <a href="http://www.smallofficeoz.com/about/">about</a> </div> </td> <td background="http://theebookagency.com/images/right_side.gif" width="44"> </td> </tr> </tbody> </table> <table border="0" cellpadding="0" cellspacing="0" width="800"> <tbody> <tr> <td background="http://theebookagency.com/images/left_side.gif" width="39"> </td> <td valign="top" width="717"> <div align="left"> <div style="text-align: left;"> <table width="700px"> <tr> <td width="400px" valign="top"> <div class="leftcolumn"> <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <div class="article" id="<?php the_ID(); ?>"> <span class="postmeta"><?php the_time('F jS, Y') ?></span> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_content('Read the rest of this entry »'); ?> <?php endwhile; ?> <br /><br /> <!-- Do other stuff... --> <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> <span class="postmeta"><?php the_time('F jS, Y') ?></span> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php endwhile; endif; ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <div class="space110"></div> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div> <div style="clear:both;"></div> </div> </div> </div> </td> <td width="300px" valign="top"> <center> <?php get_sidebar(); ?> </center> </div> </td> </tr> </table> <br> <br> </div> </td> <td background="http://theebookagency.com/images/right_side.gif" width="44"> </td> </tr> </tbody> </table> <table border="0" cellpadding="0" cellspacing="0" width="800"> <tbody> <tr> <td> <img src="http://theebookagency.com/images/bottom_bar.gif" name="USP" alt="unique "></td> </tr> </tbody> </table> </div> </body> </html> Cheers, Martin Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/#findComment-1063030 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 This shouldn't return any errors: if (have_posts()) : while (have_posts()) : the_post(); $my_query = new WP_Query('category_name=featured&posts_per_page=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; echo '<div class="article" id="<?php the_ID(); ?>"> <span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; the_content('Read the rest of this entry »'); endwhile; endwhile; endif; echo '<br /><br />'; if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) : continue; update_post_caches($posts); echo '<span class="postmeta">'.the_time('F jS, Y').'</span> <h2><a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a></h2>'; endif; endwhile; else: echo '<p>'._e('Sorry, no posts matched your criteria.').'</p>'; endif; echo '</div>'; Not sure if it will do as desired though. EDIT: Changed some of it. I'm not familiar with WP, but in theory it should work, however it is untested. Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/#findComment-1063042 Share on other sites More sharing options...
MartinNeumann Posted May 25, 2010 Author Share Posted May 25, 2010 Thanks Karl, Nope it didn't work - it's frustrating because I followed the official WP Codex Support line for line and it didn't work. Thanks for trying, though. Regards, Martin Link to comment https://forums.phpfreaks.com/topic/202839-need-a-little-help-with-a-loop-issue-in-wp/#findComment-1063048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.