• 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

    • Looks like many years since the request was made, a directory tree view finally may be added. https://github.com/files-community/Files/pull/18537
    • There's this from last year https://gist.github.com/threat...364659a8887841aa43deca4efd9 but nothing about a buffer overflow that MS somehow can't code against. No matter what, it makes sense to take a "protected by default" approach.
    • Popular Windows 11 file manager Files gets improved tags, layouts, and new OneDrive icon by Taras Buria Files, one of the best third-party file managers for Windows 11 out there, has received a minor update to version 4.1.3. The latest release brings a few quality-of-life improvements and new features, including an easier way to calculate folder sizes, improved tags, a new OneDrive icon, and more. Starting with folder size, File now has a dedicated "View size" button for each folder if you have the "Calculate folder sizes" option turned off in settings. This improves performance and allows you to see each folder's size only when needed. Note that folder size calculation could take some time depending on the number of files and their "weight." Next, Files can now retain file selection when switching layouts. While this change is rather minor, it lets you keep selected objects highlighted whenever you need to switch, say, from a list to a thumbnail layout. If you use tags, you will be glad to know that Files 4.1.3 makes it easier to remove all tags. You can do that with one of the following methods: From the context menu — right-click an item, open the Tags submenu, and choose Remove tags. From the toolbar — when the Edit Tags button is pinned to the toolbar, the same option appears in its menu. From the Command Palette — open the Command Palette and search for Remove tags. You can also assign your own keyboard shortcut to it from Settings. The final visible change is the new OneDrive icon. Files now pulls the icon directly from the OneDrive executable, which means the app always has the up-to-date version. As for the fixes, developers resolved the following bugs: Fixed an issue with extracting tar archives. Fixed an issue where the Signatures page would occasionally cause a crash. Fixed an issue where the Play action wasn’t available when a single media file was selected. Fixed an issue where Smart Extract would extract archives to the wrong location when switching tabs. Fixed an issue where tag search excluded folders when grouping by type. Fixed an issue where thumbnails would sometimes fail to refresh after a file was modified. Fixed an issue where a BitLocker-locked drive wasn’t displayed. Developers also revealed what is coming in future updates. Soon, Files Preview will get a new Tree View sidebar, allowing you to display folders in an expandable hierarchy, which is a popular way to browse deeply nested folders. Expect the feature to arrive in the preview channel in upcoming updates. You can download Files from the Microsoft Store (paid version) or its official website (free).
  • Recent Achievements

    • First Post
      DragonOfMercy earned a badge
      First Post
    • First Post
      bella52 earned a badge
      First Post
    • Reacting Well
      Techinmay earned a badge
      Reacting Well
    • Collaborator
      WndSks went up a rank
      Collaborator
    • One Month Later
      Sopa flores earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      500
    2. 2
      PsYcHoKiLLa
      211
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      84
    5. 5
      FloatingFatMan
      72
  • Tell a friend

    Love Neowin? Tell a friend!