bgbs Posted November 17, 2009 Share Posted November 17, 2009 On my homepage I have a list of latest blog posts showing. The first post is the latest one with a big picture, and the older ones go down just as regular posts. Well the problem is, the regular list posts also show the first post, and its a nag for me because it is a duplicate that I wish it would not be there since it is already showing as the Big Latest Story. How can I modify the code to not to repeat the latest story twice? This is the code that puls the latest story <?php $recent = new WP_Query("cat=1&showposts=1"); while($recent->have_posts()) : $recent->the_post();?> <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1> <?php if (function_exists('the_content_limit')) { the_content_limit(195, "<span class='read-more'>Read more »</span>"); } ?> <div style="clear:both;"></div> <?php endwhile; ?> And this is the next code that show the 5 recent stories as regular posts. I would like the first one from that recent list ommitted some how, but I dont know how to do that. <?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?> <h4><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4> <?php the_content_limit(130, ""); ?> <div class="hppostmeta"> <p><?php the_time('F j, Y'); ?> | <a href="<?php the_permalink() ?>" rel="bookmark">Read the story »</a></p> </div> <?php endwhile; ?><br /> Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/ Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 How about this? $recent = new WP_Query("cat=1&showposts=6"); $i = 0; while($recent->have_posts()) : $recent->the_post(); if($i == 0){ echo '<h1><a href="'.php the_permalink().'" rel="bookmark">'.php the_title().'</a></h1>'; if (function_exists('the_content_limit')){ the_content_limit(195, "<span class='read-more'>Read more »</span>"); } }else{ echo '<h4><a href="'.php the_permalink().'" rel="bookmark">'.the_title().'</a></h4>'; the_content_limit(130, "") echo '<div class="hppostmeta">'; echo '<p>'.the_time('F j, Y').' | <a href=".'php the_permalink().'" rel="bookmark">Read the story »</a></p>'; echo '</div>'; } echo '<div style="clear:both;"></div>'; $i++ endwhile; Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959275 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 You want me to enclose this whole code in one php bracket? If I paste your code I get the infamous parse error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wasc/public_html/news/wp-content/themes/news/home.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959310 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Yeah that would need to be between the php tags Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959316 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 yeah that is what I did, but I'm getting the parse error. line 18 in home.php page is echo <h1>....</h1> line <?php $recent = new WP_Query("cat=1&showposts=6"); $i = 0; while($recent->have_posts()) : $recent->the_post(); if($i == 0){ echo '<h1><a href="'.php the_permalink().'" rel="bookmark">'.php the_title().'</a></h1>'; if (function_exists('the_content_limit')){ the_content_limit(195, "<span class='read-more'>Read more »</span>"); } }else{ echo '<h4><a href="'.php the_permalink().'" rel="bookmark">'.the_title().'</a></h4>'; the_content_limit(130, "") echo '<div class="hppostmeta">'; echo '<p>'.the_time('F j, Y').' | <a href=".'php the_permalink().'" rel="bookmark">Read the story »</a></p>'; echo '</div>'; } echo '<div style="clear:both;"></div>'; $i++ endwhile; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959325 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Sorry about that try it now. <?php $recent = new WP_Query("cat=1&showposts=6"); $i = 0; while($recent->have_posts()) : $recent->the_post(); if($i == 0){ echo '<h1><a href="'.the_permalink().'" rel="bookmark">'.the_title().'</a></h1>'; if (function_exists('the_content_limit')){ the_content_limit(195, "<span class='read-more'>Read more »</span>"); } }else{ echo '<h4><a href="'.the_permalink().'" rel="bookmark">'.the_title().'</a></h4>'; the_content_limit(130, "") echo '<div class="hppostmeta">'; echo '<p>'.the_time('F j, Y').' | <a href=".'the_permalink().'" rel="bookmark">Read the story »</a></p>'; echo '</div>'; } echo '<div style="clear:both;"></div>'; $i++ endwhile; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959329 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 I appreciate your help ... now the parse error moved down to line 25 echo '<div class="hppostmeta">'; doesnt seem anything wrong here to me Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959346 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 simple SQL query utilizing LIMIT: <?php /* get first post; */ #get num posts to show; $limit = 1; $sql = "SELECT * FROM `your_table` ORDER BY `your_field` DESC LIMIT {$limit}"; /* get remainging 5 posts; */ #get num posts to show; $limit = 5; $sql = "SELECT * FROM `your_table` ORDER BY `your_field` DESC LIMIT 1, {$limit}"; ?> it's all in the query(s); Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959350 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 I appreciate your help ... now the parse error moved down to line 25 echo '<div class="hppostmeta">'; doesnt seem anything wrong here to me the_content_limit(130, "") is missing a closing ; Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959353 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Yeah mrMarcus beat me to it... Hopefully thats the last error youll have before seeing if it actually produces the results you want. lol Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959358 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 After adding the semicolon it's getting close, we moved one line down, now the parse error is at line 26 for some reason echo '<p>'.the_time('F j, Y').' | <a href=".'the_permalink().'" rel="bookmark">Read the story »</a></p>'; <?php $recent = new WP_Query("cat=1&showposts=6"); $i = 0; while($recent->have_posts()) : $recent->the_post(); if($i == 0){ echo '<h1><a href="'.the_permalink().'" rel="bookmark">'.the_title().'</a></h1>'; if (function_exists('the_content_limit')){ the_content_limit(195, "<span class='read-more'>Read more »</span>"); } }else{ echo '<h4><a href="'.the_permalink().'" rel="bookmark">'.the_title().'</a></h4>'; the_content_limit(130, ""); echo '<div class="hppostmeta">'; echo '<p>'.the_time('F j, Y').' | <a href=".'the_permalink().'" rel="bookmark">Read the story »</a></p>'; echo '</div>'; } echo '<div style="clear:both;"></div>'; $i++ endwhile; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959395 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 The . and ' are backwards here <a href=".'the_permalink().'" should be <a href="'.the_permalink().'" Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959403 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 that worked now the error ended at endwhile; ?> line 31 Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959412 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 LOL Grrrr the $i++ is missing its semi. $i++; should be the last woops Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959419 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 Well, it rendered without any parse errors But it's output is wrong. For example: This supposed to output title only: But it gives me perma link and then the Title. And when it outputs the title, it disregards all css because of that. http://wassoc.com/news/2009/11/dell-confirms-android-smart-phone-specs-still-secret/Dell Confirms Android Smart Phone, Specs Still Secret This is being output correctly By Charlie Sorre Source: Wired Dell has, at long last, confirmed its intentions to get into the smartphone market. The company’s... This output is incorrect also. "Read the story" is the link, but clicking on it doesn't take you to the actual story. It should display date and "Read the Story" link only. But it displays perma link too. November 14, 2009http://wassoc.com/news/2009/11/dell-confirms-android-smart-phone-specs-still-secret/ | Read the story » Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959431 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Your going to have to look at the source html thats being outputted and that should show you why this is happening. Then just change the echo statements to produce the corrected results. Post the generated html if you need help with that. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959433 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 here is the live page http://wassociation.com/news/ If you move down to "Site New" and "Polls" section, that is how the actual output should be Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959435 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Looks like the function the_permalink() is doing its own echo. So try it like this. <?php $recent = new WP_Query("cat=1&showposts=6"); $i = 0; while($recent->have_posts()) : $recent->the_post(); if($i == 0){ echo '<h1><a href="'; the_permalink(); echo '" rel="bookmark">'.the_title().'</a></h1>'; if (function_exists('the_content_limit')){ the_content_limit(195, "<span class='read-more'>Read more »</span>"); } }else{ echo '<h4><a href="'; the_permalink(); echo '" rel="bookmark">'.the_title().'</a></h4>'; the_content_limit(130, ""); echo '<div class="hppostmeta">'; echo '<p>'.the_time('F j, Y').' | <a href="'; the_permalink(); echo '" rel="bookmark">Read the story »</a></p>'; echo '</div>'; } echo '<div style="clear:both;"></div>'; $i++; endwhile; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959450 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 Now it doesnt output title at all, you can see it in the live link. This makes me wonder now, if I will ever be able to learn php. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959522 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 did you consider my post at all? a very, very simple change in the initial query(s) could have solved this mess hours ago. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959537 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 did you consider my post at all? a very, very simple change in the initial query(s) could have solved this mess hours ago. I did, but I had no idea where to start implementing it. I'm like the php newb. Do I just put your code in place of all that php code? Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959565 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 did you consider my post at all? a very, very simple change in the initial query(s) could have solved this mess hours ago. I did, but I had no idea where to start implementing it. I'm like the php newb. Do I just put your code in place of all that php code? no, you would make the changes to the query that is outputting the recent posts. post your queries here (just the queries), and i'll have a look. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959567 Share on other sites More sharing options...
bgbs Posted November 17, 2009 Author Share Posted November 17, 2009 there is like millions of files in this wordpress directory, I'm not sure which one of those files takes care of the sql queries. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959589 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 well, it was just a suggestion. don't sound so defeated. you're not going to learn PHP in a day, or a week, or a month. you need patience and the desire to learn. This makes me wonder now' date=' if I will ever be able to learn php.[/quote'] come on now, i'm not sure how old you are, but that's a very immature comment. the problem with the world these days (one of a million) is that the feeling of entitlement runs high. hard work pays off, and anything less is a fluke. put in the time, and the results will come. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959607 Share on other sites More sharing options...
bgbs Posted November 18, 2009 Author Share Posted November 18, 2009 I'm a designer by trade, when it come to php things go down from there. The problem with php, you dont even know where to start learning it. Every book starts with useless "hello world" statement, when in the real world you are faced with the database, arrays, and the whole infrastructure problems and equations to deal with. I dont know if anybody starts learning php with simple php commands, in the realworld, if you dont grasp the big picture in 10 minutes you are lost in translation. Quote Link to comment https://forums.phpfreaks.com/topic/181885-latest-post-duplicate-help/#findComment-959661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.