WordPress.org

Ready to get started?Download WordPress

Forums

Need help with bringing recent posts to my custom page template (1 post)

  1. yoshid
    Member
    Posted 1 year ago #

    hello everyone,

    if any of you good folks have the time or the energy to look over my code and let me know where Iv'e messed up, I would greatly appreciate it.
    I'm trying to bring two recent posts into a sidebar with thumbnails and text snippets. right now, this code is bringing the same post twice. I can't figure out where I've made the php error. take a look and many thanks in advance...

    -------

    <?php
    		$sql = mysql_query("SELECT * FROM wp_posts ORDER BY ID DESC LIMIT 0,1");
    			  while($FirstMostRecentPost = mysql_fetch_array($sql))
    			  {
    		?> 
    
            <div>
    		<?php
    		  $sql = mysql_query("SELECT * FROM wp_posts WHERE post_type ='attachment' AND post_parent ='".$FirstMostRecentPost["post_parent"]."' LIMIT 0,1");
    			  while($FirstMostRecentPostIMG = mysql_fetch_array($sql))
    			  {
    		?>
                <img src="<?php echo $FirstMostRecentPostIMG["guid"]; ?>" style="width:220px; height:72px; overflow:hidden" title="<?php echo $FirstMostRecentPost["post_title"]; ?>"/>
                <?php  }?> 
    
               <div class="feed_title"><a>' target='_blank'><?php echo $FirstMostRecentPost["post_title"]; ?></a></div>
               <div class="feed_snippet">
    						<?php
                            $paragraph = $FirstMostRecentPost["post_excerpt"];
    
                            $rough_short_par = substr($paragraph, 0, 110);
                            $last_space_pos = strrpos($rough_short_par, " ");
                            $clean_short_par = substr($rough_short_par, 0, $last_space_pos);
                            $clean_sentence = $clean_short_par . "<a href='http://scienceofhearing.ca/?p=".$FirstMostRecentPost["post_parent"]."'>...read more</a>";
                            echo $clean_sentence;
    
                            ?>
              	</div>
              </div>
    
               <?php  } ?> 
    
    		<?php
    		$sql = mysql_query("SELECT * FROM wp_posts ORDER BY ID DESC LIMIT 0,1");
    			  while($SecondMostRecentPost = mysql_fetch_array($sql))
    			  {
    		?> 
    
            <div>
    		<?php
    		  $sql = mysql_query("SELECT * FROM wp_posts WHERE post_type ='attachment' AND post_parent ='".$SecondMostRecentPost["post_parent"]."' LIMIT 0,1");
    			  while($SecondMostRecentPostIMG = mysql_fetch_array($sql))
    			  {
    		?>
                <img src="<?php echo $SecondMostRecentPostIMG["guid"]; ?>" style="width:220px; height:72px; overflow:hidden" title="<?php echo $SecondMostRecentPost["post_title"]; ?>"/>
                <?php  }?> 
    
               <div class="feed_title"><a>' target='_blank'><?php echo $SecondMostRecentPost["post_title"]; ?></a></div>
               <div class="feed_snippet">
    						<?php
                            $paragraph = $SecondMostRecentPost["post_excerpt"];
    
                            $rough_short_par = substr($paragraph, 0, 110);
                            $last_space_pos = strrpos($rough_short_par, " ");
                            $clean_short_par = substr($rough_short_par, 0, $last_space_pos);
                            $clean_sentence = $clean_short_par . "<a href='http://scienceofhearing.ca/?p=".$SecondMostRecentPost["post_parent"]."'>...read more</a>";
                            echo $clean_sentence;
    
                            ?>
              	</div>
              </div>
    
               <?php  } ?>

    --------

Topic Closed

This topic has been closed to new replies.

About this Topic