• 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

    • There is a lot of reasons not to use Edge but faster fixes and security updates is not one of them.
    • Can't reproduce. I installed Edge, went to neowin.net > accepted the cookie consent > used menu to go to forums, everything loads and I can browse around the forums. If you can't interact with the dialog on the forums for some reason, go to the main site and accept the cookie consent there? It is true that the site will not function properly until the cookie consent is accepted or rejected,. it's a legal requirement and I also know that certain VPN/ad blockers block it, which is a user related issue and not a neowin.net problem.   This is not our cookie consent dialog. Gotta love browser hijacking... /s Edit: this may be what Californians see, I will confirm with our consent provider.
    • Google Chrome 149.0.7827.115 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | Direct Link | 131.0 MB Download: Google Chrome Offline Installer 32-bit | Direct Link | 119.0 MB Download page: Google Chrome Portable Download: Chrome ARM64 | Direct Link View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Oh, it's happening on more than one dialog? This is the dialog that I'm unable to interact with.
    • WSCC - Windows System Control Center 10.0.3.8 by Razvan Serea Windows System Control Center is a free, portable program that allows you to install, update, execute and organize the utilities from various system utility suites. WSCC can install and update the supported utilities automatically. Alternatively, WSCC can use the http protocol to download and run the programs. WSCC is portable, installation is not required. Extract the content of the downloaded zip archive to any directory on your computer. Free for personal use. The setup packages and updates are downloaded directly from their author's website! This edition of WSCC supports the following utility suites: Windows Sysinternals Suite (including support for "Sysinternals Live" service) NirSoft Utilities Mitec and more... WSCC - Windows System Control Center 10.0.3.8 changelog: [NEW] update progress is now visible on the Windows taskbar [FIXED] fixed an issue with the Update dialog [FIXED] minor fixes Download: WSCC (64-bit) | 5.4 MB (Free for personal use) Download: WSCC (32-bit) | 6.3 MB View: WSCC Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
    • Rookie
      FBSPL went up a rank
      Rookie
    • First Post
      davidbazooked earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      492
    2. 2
      PsYcHoKiLLa
      170
    3. 3
      +Edouard
      164
    4. 4
      Steven P.
      85
    5. 5
      ATLien_0
      77
  • Tell a friend

    Love Neowin? Tell a friend!