Jump to content

Latest Post duplicate help


bgbs

Recommended Posts

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 />

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

Well, it rendered without any parse errors  :D

 

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 »

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.