Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här displayed du senaste inlägg i WordPress

Precis som WPBeginner visar många populära bloggar en lista över de senaste inläggen. Det beror på att visning av senaste inlägg är ett bra sätt att hålla besökarna engagerade och komma tillbaka för mer.

När människor ser ditt senaste och bästa innehåll är det mer sannolikt att de klickar, läser och spenderar tid på att utforska din webbplats. Det gör att din webbplats känns fräsch och spännande.

Det bästa är att du kan lägga till dessa listor över senaste inlägg nästan var som helst på din WordPress-webbplats, t.ex. i sidofältet, i slutet av en artikel eller till och med i sidfoten.

I den här artikeln visar vi dig några enkla sätt att lägga till en lista över senaste inlägg på din webbplats, oavsett var du vill att den ska visas. Gör dig redo att hålla dina besökare hooked på ditt fantastiska innehåll.

How to display recent posts in WordPress

Varför lägga till senaste inlägg i WordPress?

Om du har run en WordPress blogg eller website under en längre tid, så kanske du har några äldre artiklar som får regelbunden trafik från search engines och andra källor.

Många av besökarna kommer att kontrollera den information de letade efter och lämna. Mer än 75% av dessa visitors kommer aldrig att se your website igen.

För att få användare att komma tillbaka till din website måste du se till att de tillbringar mer tid på din website.

Ett sätt att göra detta är att visa dem andra senaste inlägg som de borde se. Detta hjälper användare att upptäcka mer content på din website, vilket leder till att de spenderar mer tid på din website.

När användarna viewar fler pages får du tid att övertyga dem om att anmäla sig till ditt nyhetsbrev eller göra ett köp.

Med detta sagt, låt oss ta en titt på hur du enkelt kan visa senaste inlägg i WordPress med hjälp av flera metoder. Du kan klicka på snabblänkarna under för att hoppa direkt till olika metoder:

Video Tutorial

Subscribe to WPBeginner

Om du föredrar skriftliga instruktioner är det bara att fortsätta läsa.

Metod 1: Använd WordPress senaste inlägg Gutenberg Block

WordPress Block Editor (Gutenberg) har ett built-in block för att visa dina senaste post. Du kan enkelt add to detta till alla posts eller pages på din site.

För att använda detta block, redigera helt enkelt det post där du vill visa senaste inlägg. På vyn för edit av post måste du add to blocket ”Latest Posts” till content area.

Add latest posts block

Det finns många olika sätt du kan konfigurera det här blocket. Som standard visar det bara rubrikerna på posterna, men du kan enkelt customize det.

Till exempel kan du toggle post content på och av i den högra rutan. Detta gör att du kan välja att add post content eller excerpt nästa inlägg till titeln.

Du kan också customize längden på excerptet, som standard är 55 ord, men du kan välja valfritt värde mellan 10 och 100 ord.

Show post content in recent posts

Om du vill kan du också visa postdatum och författare till posten.

Aktivera bara alternativen ”Display post date” och ”Display author name” under Metadata för inlägg Settings.

Display post date and author

You kan också välja exakt hur dina posts ska visas. You can order them differently from the standard ”Newest to Oldest”, and you can show only the latest posts from a specific category.

Från panelen Settings kan du också välja hur många posts som ska visas. Som standard visar blocket 5 posts, men du kan visa allt mellan 1 och 100 posts.

Sort and filter recent posts

Du har också alternativet att visa dina senaste inlägg i ett column grid snarare än en lista.

Välj helt enkelt alternativet ”Grid view” i toolbaren.

View latest posts in grid view

Du kan customize gridden med hjälp av settings till höger på vyn.

Till exempel kan du visa featured images för dina inlägg, resize bilderna och justera dem i enlighet med detta.

Show featured images in latest posts

När du är slutförd kan du förhandsgranska posten för att se den på din website.

Så här ser det slutförda blocket ut Live på vår test site.

Latest posts preview

Metod 2: Använd WordPress Widget Block för senaste inlägg

Tänk om du vill visa en lista över dina senaste posts i din sidebar istället för på en page? WordPress levereras med en built-in standardwidget för att visa senaste inlägg i din sites sidebar eller något annat widget-klart area.

I din WordPress dashboard, gå till Appearance ” Widgets och add the ’Latest Posts’ widget block till din sidebar.

Add latest post widget block

You can then customize the appearance of your recent posts in the sidebar.

WordPress låter dig till exempel visa inläggets content, auktorisera inlägget och visa datum, aktivera featured images och sortera dina senaste inlägg.

Customize recent posts widget block

När du är klar klickar du på knappen ”Update” för att lagra dina inställningar för widgetar.

Här är widgeten live på bloggen, med titeln ”New Posts” och datum aktiverade:

Latest posts in sidebar menu

Metod 3: Använd widget för senaste inlägg med inläggsminiatyr-plugin

Den built-in widget som vi nämnde ovan är ganska limit.

Vad händer om du vill visa inläggsminiatyrer och excerpt med dina senaste inlägg? Vad händer om du bara gillar att visa posts från en viss kategori i din sidebar?

Det är då pluginet Recent Posts Widget With Thumbnails kommer väl till pass. Det gör mycket mer än bara thumbnails, och det är gratis.

Först måste du installera och aktivera pluginet WordPress Recent Posts Widget With Thumbnails.

Gå sedan till sidan Appearance ” Widgets och lägg sedan till widgetblocket ’Senaste inlägg med inläggsminiatyrer’.

Add recent posts with thumbnails widget block

Widgeten Senaste inlägg med inläggsminiatyrer kommer med många alternativ. Den ger dig full control över hur du vill displayed senaste inlägg på din WordPress site.

Du kan också visa excerpt, visa inlägg från specifika kategorier, ignorera (fast)klistrade inlägg, välja antal inlägg som ska visas, auktoriseringar med mera.

Customize recent posts with thumbnails

När du är klar, glöm inte att klicka på knappen ”Update” för att lagra dina inställningar.

Du kan nu besöka din website för att se dina senaste inlägg med thumbnails.

Recent posts widget with thumbnails preview

Metod 4: Visa senaste inlägg med hjälp av en shortcode

Att använda blocket ”Senaste inlägg” är definitivt det enklaste sättet att visa de senaste inläggen i WordPress inlägg och pages. Men om du väljer att inaktivera Gutenberg och behålla Classic Editor kan du använda shortcodes istället.

Först installerar och aktiverar du det relevanta pluginet. Om du behöver hjälp, vänligen se vår guide om hur du installerar ett plugin för WordPress.

Det är ett av de mest populära tillägg för post för WordPress. Du får flera options för att customize utseendet på dina senaste inlägg, som att editera rubriken, antalet inlägg, välja om du vill visa en featured image, excerpt, inläggsdatum, och mer.

Change relevant settings

Därefter redigerar du helt enkelt ett inlägg eller en page där du vill visa dina senaste inlägg och använder sedan shortcode [bws_latest_posts].

Så här såg vår lista över senaste inlägg ut med hjälp av dessa instruktioner:

Display recent posts shortcode

Metod 5: Display senaste inlägg manuellt i WordPress

Mer avancerade WordPress-användare kanske vill add senaste inlägg direkt till sina WordPress-temafiler. Naturligtvis bör du använda ett barntema för detta så att du inte förlorar dina ändringar när du uppdaterar ditt tema.

Det är alltid en bra idé att skapa en backup innan du editerar dina theme-filer. Om något går fel kan du ta en titt på vår lista över de vanligaste WordPress error och hur du fixar dem.

Det enklaste sättet att manuellt visa senaste inlägg är att använda den built-in WP_Query-klassen. Lägg bara till den här koden där du vill visa de senaste inläggen:

<ul>
 
<?php
// Define our WP Query Parameters
$the_query = new WP_Query( 'posts_per_page=5' ); ?>
 
<?php
// Start our WP Query
while ($the_query -> have_posts()) : $the_query -> the_post();
// Display the Post Title with Hyperlink
?>
 
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
 
<li><?php
// Display the Post Excerpt
the_excerpt(__('(more…)')); ?></li>
 
<?php
// Repeat the process and reset once it hits the limit
endwhile;
wp_reset_postdata();
?>
</ul>

Den här koden visar de fem senaste inläggen med deras titlar och excerpt. WP_Query-klassen har massor av parametrar som gör att du kan customize den på vilket sätt du gillar. Mer information finns vänligen i dokumentationen för utvecklare av WordPress.

Expertguider om att rekommendera publicerade posts i WordPress

Vi hoppas att den här artikeln har hjälpt dig att lära dig hur du visar de senaste inläggen i WordPress. Du kanske också är intresserad av några andra artiklar som handlar om att marknadsföra innehåll till dina läsare:

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

141 kommentarerLämna ett svar

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Louise

    Hi,
    Thank you for this post. Really helped a lot.
    But then I have a problem. When I click on one of the recent posts – it directed me to the static page and not the post itself. Kindly help me resolved this issue. Thank you.

    • WPBeginner Support

      Try updating your permalink structure. Simply visit Settings » Permalinks and then click on the save changes button without changing anything.

      Administratör

  3. Ellen Allard (Gluten Free Diva)

    So glad to have found you!

    I’m confused – I can’t seem to get my most recent blog post to appear on my blog page. Can you advise please? Thank you so much!

    best, Ellen Allard, Gluten Free Diva

  4. Tim Zeman

    So I was able to get the 5 latest post to show in the right sidebar but when I click on a post to read it I get the following error on Home Page Oops something went wrong

    How do I get the selected post to display?

  5. John Mason

    Are links to the recent posts widget dofollow links?

  6. Val Archer

    Hi – thanks million for this manual method, very grateful. Please can you tell me how to add a thumbnail image to it? I’m referring to the method starting:

    // Define our WP Query Parameters

    • Rajkumar

      hello,
      To display a thumbnail image u can ues

    • Andrew Wilkerson

      Hi Val, Hope your doing well, I was just scrolling through this article and saw your name and thought straight away I know that name! It’s a small world.
      I made one of your sprouters in the late 90’s I think it would have been.
      Funny thing is I was just thinking about building another one a few days ago!

      Crazy how things happen sometimes!
      Weird that I then just stumbled across your comment on here today in 2018 while I’m working on my website for something totally unrelated.

      I remember I really enjoyed reading about your life and the move to Sth Africa, your cures for tooth aces etc. I’ll have to have another look into it all again soon when I have time, anyway just thought I’d say Hi.

  7. Farhad

    Hello, I used the same shortcut in my site but it not show my recent posts at all, what is the probelm?

    • WPBeginner Support

      This article shows several ways to display recent posts, which one you tried on your website?

      Administratör

  8. Marcio

    Hey, how to display recent posts from another wordpress site?

  9. Joe

    Hi,

    On my recent posts on the sidebar, when I click a specific post it brings me to the latest post and then displays everything. How do I get it so that when I click a specific post it only shows that post?

    Thanks!

  10. Sally

    Is there a code I can add to activate pagination using the Recent Posts Extended widget?

    Currently I have my home page widgetized so I’m using the widget.

    Thanks!

  11. alin dragoescu

    Hello,

    Please let me know if it’s posible to show the post list in dropdown?

  12. Nick NEvsky

    Hi! Great plugin, thank you!
    Is it possible to have the author listed, instead of the post name?
    Thanks!

  13. Jason

    The version I downloaded does not include the ability to display thumbnails…cant see the option anywhere. I am using version 0.9.9

    Any clues?

  14. andrea

    Hi, my issue is to display the latest post full content in a static home page… and i was thinking that the last snippet was what i needed… but unfortunately it does not works properly. In effects it shows title but not the content. could u help me please

  15. Tushar

    Hi I am new on wordpress, I want to show Client Testimonial using post….How should I do it..? any suggestions please ?

  16. WPBeginner Staff

    Here is an easier way. Install Display Posts Shortcode plugin. Create a blank page and add the shortcode as described in plugins documentation. Publish the page. Go to Settings > Reading and select the page you just created as your static page. Redit the static page and add the slider just before the display posts shortcode. Hope this helps you.

  17. Emily

    Hi, I am wanting to add a slider to the top of my homepage, but it will only allow me to do so if I use a static page. Right now when you go directly to my website, it is my latest posts in full length. If I change my homepage to a static page so that I can include the slider, will this work to add the recent posts below, just as it appears now? Where would I be posting this code? Into the static homepage?

    Note– I recently tried messing with my php and broke my code and had some major issues.. so I’m pretty nervous messing with php.

  18. Subrata

    hi!…can anyone tell me how to display top rated blog posts (only 5) in increasing order (numeric order) by using PHP codes?

  19. Oliver

    Hi there. I am a designer so I’ve never been good at PHP. At least I can read and change it for my conditions most of the time. This time I’d like to call for the nine latest posts excluding the very last one inside my slideshow container.

    For now I just set the first post on display none. This works fine; however the slideshow still counts to ten. That’s why you find the last page empty.
    Is there any way to exclude the very last post when calling for recent posts? Thank you so much in advance!

  20. KalanaDe

    Hi, I want to display blog posts only from a category called ’Blog’ only. (I want to exclude all other posts from other categories.) What should I add to this code.?

  21. Bucur

    showposts is deprecated. However, posts_per_page is perfect for use with query_posts(), or even more particularly, WP_Query::query().

    numberposts may be the equivalent argument for get_posts().

  22. Dan

    This worked perfect! Thanks a lot to the author of this article.

  23. Gabriel

    The link to Limit-Post Plugin doesnt work!?

    • WPBeginner Support

      Thanks for notifying us. We have updated the article with a new code snippet that does not require you to install any plugins. Hope this helps.

      Administratör

  24. Art

    Good article.

    One piece of info that would increase it’s usefulness though, is how to (or a plugin that can) include an offset.

    For example, I want my two most recent posts to be full text — got that.
    But what if I want the next 10 to be excerpts, and maybe the next 10 older to be headlines only — the list?

    So — how can you include an offset?

    Cheers,
    Art

  25. Ryan

    Hi there,

    I want my latest 4 posts to display inline across the screen, how would I do this?

    Currently they only display down the page.

    Thanks

    Ryan

    • Mike

      Sounds like you need to create a container with the height/width you want the posts to appear as. Then allow them to wrap over.. make sure that the last piece of your ”Post” code doesn’t have a line break.

  26. Wilko

    Great post! Thanks!

    Just one question. Is it possible to hide the latest post out of 5? I mean on my website I display the latest post already with full content, so I would like to hide the first.

  27. Captain Code

    Exactly what I was looking for!

    Thank You =)

  28. Actors Alliance

    Where do I input the code to change the number of full posts displayed?

  29. Amanda

    Lovely! Is there a way to make the headers of each post H2 ? And, can I hide a category?

    • Editorial Staff

      Yes use the second method and wrap it around h2. Use wp_query codex page to look at the parameter for hiding categories.

      Administratör

  30. Jeremy

    Finally a quick and to the point tutorial on this topic. Other posts on calling in the recent blog posts were not as quick and too the point. Thanks :D

  31. Ellery Davies

    Hi Syed,

    I use the WordPress Twenty-Eleven theme and have always displayed recent posts using the widget in Jetpack. But I want this list to show in the individual posts as well. Is there a way to do this? If it involves pasting code, into which file do I paste?

    • Editorial Staff

      Where in the individual posts do you want to show that list? Below post? Sidebar?

      Administratör

      • Ellery Davies

        The home page of AWildDuck -d0t- com, shows recent posts along the right side, along with subscribe and a tag cloud. But this appears only on the home page. If I send you a link to any individual post (or if you click on the title of any post), the right frame disappears. My visitors can no longer see a list of recent posts. I am very frustrated by this, and I want to know how to get that list of recent posts to appear on all pages. (Not just the home page).

        • Editorial Staff

          Go to Appearance > Theme Options. Change the default Layout to content on left.

        • Ellery Davies

          Hi Syed,
          Indeed, this is my current setting. It has always been my setting. Twenty Eleven with ”Content on left”.

        • Editorial Staff

          Hmm that’s weird because that’s what I have and it is working fine.

        • Ellery Davies

          I don’t understand… Do you see Recent Posts on the right, even when you are looking at an individual post? If you do, are you using JetPack/Recent Posts?

          If the answer to both questions is ”Yes”, would you please send me your phone number. You already have my email address. -Or call me: Area code ”Five-Oh-EIght”, 485 ..695O.

          Thanks, –Ellery

  32. darknote

    Thank you and with the_post_thumbnail ?

    • Editorial Staff

      Simply add the_post_thumbnail(); and style it however you like.

      Administratör

      • darknote

        thank you, yes, but I ask not only for me but thinking of other visitors, it can be more useful in your article, give an example of recent articles with thumbnails.

      • Kylie

        Thanks so much for this tutorial! I used the code to display recent posts with a summary on my website’s homepage.

        When adding the_post_thumbnail(); code could you please tell me what file and where in the file to add it? I tried looking it up and experimented by adding it to several files on my own and was not able to get the thumbnails to show up.

        Any insight would be greatly appreciated.

        Thank you,

        Kylie

        • WPBeginner Support

          In your Post Edit area, post thumbnails are called featured image. If you can not see a featured image meta box, then click on Screen Options button on the top right corner of your post edit screen and check Featured image.

  33. vajrasar

    Nice Post.
    How can I achieve – Recent Posts in Menu. Like I have my category ”Crime” on top-menu. Now whenever a user hover it, I want to show 5 recent posts from category ”Crime” with their thumbnails?

  34. muhabas

    Spent a lot of time to find out this information which works for me 100%. Its very easy and to the point. Thanks…… God bless you.

  35. wanted20

    Hello. I have a website with 3 subdomains. It’s possible to display in a widget in the main domain the lastest posts from a subdomain?

  36. cwdcreative

    The link to the ”limit-post” plugin does not work. Do you have a current link or an alternate?

    Thank you!

  37. broghanreilly

    I have tried to use this code and it doesn’t seem to work? I am a beginner and am using a standard theme and not hosting. Therefore I can’t upload anything I can only use HTML.

  38. doodark

    Thanks so much for posting such a useful and concise article. Much appreciated!

  39. YiLiu

    very usefull for me.thanks

  40. Tiago Araujo

    Thank you very much for the post, I was looking for it for a while and found your explanation pretty simple and useful. Code worked just fine for me!

  41. Panoz

    My WP homepage has a footer displaying the titles of my 4 latest posts (Recent Posts). This makes no sense, as these posts are already displayed above.

    My question is how can my footer display the range between 5th and 8th post ??

    The code its currently using is

    <?php wp_get_archives('type=postbypost&limit=5');

    Many thanx in advance for your help

    • Editorial Staff

      You can’t use wp_get_archives for that. You would have to run a loop and add the query_post function with the offset parameter.

      Administratör

      • Panoz

        Thank you very much for your kind reply. Can you please let me know how I can do that? I know very few stuff and i definately need to have this done by the day after tomorrow that I’m launching my site.
        Thanks

  42. Phelan

    I’ve been looking for this code for a few days now. I can’t believe it’s not more readily available in the Template Tags pages or any other blogs.

    I changed the code to include tags and tags instead of the tags like the following:

    <a href="”>

    Thanks for posting!

  43. Katie

    One problem with the above code is when you call that function in your sidebar which is called before the start of the loop in single.php. Your single.php file will list down all the articles of your blog post irrespective of the one which is called.

    In such cases, you can also use

    Otherwise, calling query_posts(’showposts=10’); function is fine.

    Both of them will list down latest 10 posts in ul, li format. This is bit easier.

  44. Mike

    Hi, is it possible to show the date before the linked post title when using:
    <?php get_archives('postbypost', '10', 'custom', '’, ”); ?>

    Thanks

  45. ali

    Hi Guys

    I seem to be having some issues with this code. It works great on my index.php page but when I try adding it to either the page.php or single.php it prevents other content showing. For example when I click the ’about us’ page it will display the latest article!

    Hope this makes sense and any help anyone can offer would be greatly appreciated.

    Thanks

  46. ravi

    i want to display posts in order of post date.. recent one first with pagination i am able to do the pagination but the posts are displaying on each page in random order somebody please help………….:(

    • Editorial Staff

      Don’t see why it wouldn’t display posts in the order of date. The loop method would only display the most recent ones at the top.

      Administratör

  47. Abhijit V. Chaore

    There were few articles around explaining the same thing. But you elaborated the topic with additional information which is very useful. Thanks for your efforts.

  48. seminyak bali

    How about on spesific page – example i make new page called blog, i have try the code but get error,

  49. Mark

    I want to know how to display rcenet posts with thimthumb thumbnial.

    Unfortunately Google is being Google as usual and not giving me the results I want.

    Thanks.

    • Editorial Staff

      You can simply add timthumb codes anywhere in these codes, and it should work. The query will be run the exact same way. If you are looking for a step by step guide, we haven’t written one. Although we might write one in the future.

      Administratör

  50. DaveK

    I am so glad I found this, I have been trying to do this for days and I couldnt find exactly how to do this on the wordpress codex !!! the only sollution they seemed to offer screwed up the custom homepage I built, but this works perfect.

    Thanks very much.

  51. Justin

    Good info!

    I’m trying to display the latest 5 posts using the last method you described, but I can’t figure out how to get page numbers. For example, the faux blog page displays the last five posts, but there is no way to go back in time from there.

    I have not been able to find a solution for this. Any suggestions?

    Thanks!

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.