• 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.
  • Posts

    • One of my PC's is Windows 11 Home Edition... and guess what? it supports Hyper-V Disks and Containers, as well as WSL2... which these desktop tools leverage on an as-needed basis. It does not need to be enabled system-wide; it merely needs to exist. Furthermore, I tried something yesterday with Hermes Desktop and their "installer" actually builds everything from source as part of its installer toolchain! The installer (and updater as it were) both go through a roughly 19-step process to prep the system for the tool to be used -- and connectivity to local/remote models, local/remote agent configs, and other steps are not included as part of this process (those are all user config steps post-install). ALSO, the "bug wasn't confirmed to exist" is the weakest argument against a bug. That's literally every flawed product's knee-jerk reaction! Even politicians, lawmakers, murderers, and other violent criminals start with that defense... "I deny everything I'm accused of." The bug is the (shared) experience. Whether it's truly Claude Code's fault, or user error, or some other software package being the ultimate culprit, is not the point. They are experiencing unpleasant side effects and don't like that.
    • Each generaton has its exciting times and I was fortunate enough to be right there at the beginning of the PC industry.   I don't think any of us at that time realized how large it would become I still remember working on a TRS-80 with a green screen monitor that kept overheating and dying.     Also used some TRS-80 PCs with tape cartridge memory.   They worked but boy were they slow with everything being a very slow sequential read or write.  But heh, they worked though it wasn't long before they were repaced by the HDD. 
    • One Drive should be a four letter word. First thing I disable on my computer. If I want to upload something to the cloud, I use a cloud base storage, NOT microsoft. Oh but what about backup. I have done backups since floppy disk eras...it just comes naturally.
    • It does just not OneCloud. 🤷🏻‍♂️
    • Claude Desktop on Linux doesn’t have ram issues. Strange. 🤷🏻‍♂️
  • Recent Achievements

    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      515
    2. 2
      PsYcHoKiLLa
      208
    3. 3
      +Edouard
      160
    4. 4
      Steven P.
      96
    5. 5
      ATLien_0
      81
  • Tell a friend

    Love Neowin? Tell a friend!