• 0

Wordpress Help (Recent Post Question)


Question

If you remember me, I've been working on the company website for almost a year. Well the content is not all to me yet. No surprise but I'm learning Wordpress and going to get it working using Starkers 4.0 which is a strip down version of wordpress for creating Wordpress theme.

http://viewportindustries.com/products/starkers/

Anyway, I'm trying to get the recent blog post to feed to my homepage but it's only showing the first recent post and repeating it 2 times which I want to show the last 3 recent blog post with the feature image in it. Can anyone help me?

http://www.romabio.com/test/


<!-- Blog Section -->
<div class="blog-Wrap">

<ul>

<?php query_posts("showposts=3"); the_post(); ?>

<li>
<a href="<?php the_permalink(); ?>">
<div class="date-Wrap">
<div class="blog-Month"><?php the_time('M'); ?></div>
<div class="blog-Day"><?php the_time('d'); ?></div>
<div class="blog-Bar"></div>
</div>
<div class="blog-img">
<img src="<?php the_post_thumbnail('homepage-thumb'); ?>" />
</div>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</a>
</li>

<?php query_posts("showposts=3"); the_post(); ?>

<li>
<a href="<?php the_permalink(); ?>">
<div class="date-Wrap">
<div class="blog-Month"><?php the_time('M'); ?></div>
<div class="blog-Day"><?php the_time('d'); ?></div>
<div class="blog-Bar"></div>
</div>
<div class="blog-img">
<img src="<?php the_post_thumbnail('homepage-thumb'); ?>" />
</div>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</a>
</li>

<?php query_posts("showposts=3"); the_post(); ?>

<li>
<a href="<?php the_permalink(); ?>">
<div class="date-Wrap">
<div class="blog-Month"><?php the_time('M'); ?></div>
<div class="blog-Day"><?php the_time('d'); ?></div>
<div class="blog-Bar"></div>
</div>
<div class="blog-img">
<img src="<?php the_post_thumbnail('homepage-thumb'); ?>" />
</div>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</a>
</li>

</ul>

<?php wp_reset_query(); ?>

<div class="blog-Button">

<div class="button"><a href="#" title="Blog">View Blog</a></div>

</div>

</div>
<!-- Blog Section -->
[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1155882-wordpress-help-recent-post-question/
Share on other sites

14 answers to this question

Recommended Posts

  • 0

Well your query loop is all wrong and doesn't actually loop over anything. I suggest you do some reading about the loop and PHP. http://codex.wordpress.org/Function_Reference/WP_Query.

the whole point of a loop is so that you dont have to repeat yourself as you have done.

You should use a new WP query and a while loop.

so to correct your code you could cut it down to the following:

&lt;?php $my_query = new WP_Query('posts_per_page=3'); ?&gt;
&lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
  &lt;li&gt;
     &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;         
        &lt;div class="date-Wrap"&gt;
           &lt;div class="blog-Month"&gt;&lt;?php the_time('M'); ?&gt;&lt;/div&gt;          
           &lt;div class="blog-Day"&gt;&lt;?php the_time('d'); ?&gt;&lt;/div&gt;          
           &lt;div class="blog-Bar"&gt;&lt;/div&gt;         
         &lt;/div&gt;         
         &lt;div class="blog-img"&gt;          
            &lt;img src="&lt;?php the_post_thumbnail('homepage-thumb'); ?&gt;"&gt;         
          &lt;/div&gt;         
          &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt;
         &lt;?php the_excerpt(); ?&gt;    
         &lt;/a&gt;   
&lt;/li&gt;
&lt;?php endwhile; ?&gt;

But I would suggest you read up on what the code is actually doing so you can understand and implement it correctly with WordPress in the future.

  • 0

Neowins messing up for some reason.

Heres the code:

&lt;?php $my_query = new WP_Query('posts_per_page=3'); ?&gt;
&lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
  &lt;li&gt;
     &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;         
        &lt;div class="date-Wrap"&gt;
           &lt;div class="blog-Month"&gt;&lt;?php the_time('M'); ?&gt;&lt;/div&gt;          
           &lt;div class="blog-Day"&gt;&lt;?php the_time('d'); ?&gt;&lt;/div&gt;          
           &lt;div class="blog-Bar"&gt;&lt;/div&gt;         
         &lt;/div&gt;         
         &lt;div class="blog-img"&gt;          
            &lt;img src="&lt;?php the_post_thumbnail('homepage-thumb'); ?&gt;"&gt;         
          &lt;/div&gt;         
          &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt;
         &lt;?php the_excerpt(); ?&gt;    
         &lt;/a&gt;   
&lt;/li&gt;
&lt;?php endwhile; ?&gt;

Oh and your code is completely invalid as you cant have all that in an anchor tag.

Showposts in a WP_Query is also deprecated.

  • 0

Neowins messing up for some reason.

Heres the code:

&lt;?php $my_query = new WP_Query('posts_per_page=3'); ?&gt;
&lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
  &lt;li&gt;
	 &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;		
		&lt;div class="date-Wrap"&gt;
		   &lt;div class="blog-Month"&gt;&lt;?php the_time('M'); ?&gt;&lt;/div&gt;		  
		   &lt;div class="blog-Day"&gt;&lt;?php the_time('d'); ?&gt;&lt;/div&gt;		  
		   &lt;div class="blog-Bar"&gt;&lt;/div&gt;		
		 &lt;/div&gt;		
		 &lt;div class="blog-img"&gt;		  
			&lt;img src="&lt;?php the_post_thumbnail('homepage-thumb'); ?&gt;"&gt;		
		  &lt;/div&gt;		
		  &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt;
		 &lt;?php the_excerpt(); ?&gt;	
		 &lt;/a&gt;  
&lt;/li&gt;
&lt;?php endwhile; ?&gt;

Oh and your code is completely invalid as you cant have all that in an anchor tag.

Showposts in a WP_Query is also deprecated.

Thanks for the code fix! It's in HTML5 and you can put DIV tags in an anchor tag.

  • 0

No, I mean if you go to the w3 site it will pass!

w3 won't check those kind of things, it only checks if you use correct css and html tags without typos and forgetting to close them but not if a html tag is in another html tag :p

Anyway you should be using <p> tags for text instead of div, div isn't meant to be used everywhere >.>

  • 0

Whats wrong with WordPress?

Can be a nightmare to work with. In my work we have a few clients who insist on using it and it's always more hassle than it needs to be. Some truly dumb stuff can happen in it. Plugins that interfere and make the whole system inoperable. Similarly plugins that seem to magically "fix" everything when you install them again. Wordpress keeps a "database version" in a table but can also allow it to move out of sync with the rest of the installation again causing much mirth and comedy. Generally be very afraid when you see "one click install!" or "easy update!" mentioned anywhere near it. Run it on a windows based server and there can be no end of weird permissions errors that crop up from time to time.

No doubt in a lot of cases it does the job. It has plenty of features and often it's relatively simple to work in. However on the flip side it usually has "too many features" for the average user because it tries to be all things to all men. Once you need to do something out of the ordinary you spend your entire life seemingly hacking functions and loops to get it to what you need. And because so many hands touch it the code can sometimes make next to no sense. Overall it just has the feel that it's one sticking plaster away from falling to pieces around you. It's certainly not a "precision tool".

  • 0

Can be a nightmare to work with. In my work we have a few clients who insist on using it and it's always more hassle than it needs to be. Some truly dumb stuff can happen in it. Plugins that interfere and make the whole system inoperable. Similarly plugins that seem to magically "fix" everything when you install them again. Wordpress keeps a "database version" in a table but can also allow it to move out of sync with the rest of the installation again causing much mirth and comedy. Generally be very afraid when you see "one click install!" or "easy update!" mentioned anywhere near it. Run it on a windows based server and there can be no end of weird permissions errors that crop up from time to time.

No doubt in a lot of cases it does the job. It has plenty of features and often it's relatively simple to work in. However on the flip side it usually has "too many features" for the average user and once you need to do something out of the ordinary you spend your entire life seemingly hacking functions and loops to get it to anything. Overall it just has the feel that it's one sticking plaster away from falling to pieces around you.

Well for a start this threads issue was really nothing to do with WordPress. It was a lack of understanding of a php concept (loops).

I would say any CMS can be a nightmare to work with, especially if you dont know what you are doing.

The plugin issue is again not really WordPress's fault.

I have come across the database issue though lol. Was an easy fix however and the site had been moved across numerous hosts by loads of different people.

I suppose stuff like that teaches you the value of good backup systems.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.