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

カテゴリー: WordPressで最終更新投稿リストを表示する方法

WPBeginnerでは、すべての投稿に公開した日付の代わりに最終更新日を表示しています。WordPressブログの投稿から日付を削除するのは悪い考えだと考えています。最終更新日を使用している場合、最近更新された投稿のリストをサイトに表示したいと思うかもしれません。この投稿では、WordPressで最終更新日の投稿リストを表示する方法を紹介する。

WordPressは投稿を更新するたびに、その更新日時を最終更新日時として投稿テーブルに保存します。WordPressのカスタムクエリーを作成して、最近更新された記事を一覧表示する方法を紹介します。

このコードをサイト固有のプラグインまたはテーマのfunctions.phpファイルにコピー&ペーストしてください。

[cbk1]

これですべてです。あとは、テーマのテンプレートファイルに最終更新投稿を表示させたい場合は、以下のように使います:

[cbk2]

WordPressの投稿、ページ、ウィジェットに最終更新日時を表示するには、ショートコード[SKX1]を使います。

WordPressで投稿を並べ替えるには、さまざまな方法があります。昇順、降順、ランダムの他に、有効期限で投稿を表示することもできます。この投稿では、最終更新日時順に投稿を表示することができます。

あなたのサイトではどのように使いますか?オリジナルの公開日や最終更新日を表示していますか?下のコメント欄からお知らせください。

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

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.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

37件のコメント返信を残す

  1. Thomas Mirke

    Hi,
    i modified the code from “modified” to “date”. Then i noticed, that $lastupdated_loop->have_posts() is limited to the number of last posts which is presented on the main page. What is to do to get an (independent) number of f.e. 50 last posts? Instead of 6 as stored in the wp settings?

    • WPBeginner Support

      You should be able to change from line 12 of the code the section ‘&& $counter < 5' and change the 5 to the number of posts you want to show.

      管理者

      • Thomas Mirke

        Thank you, you can be sure, that this was the first thing i did. But notice that when you change the number in your code it is without result. Write f.e. ‘&& $counter <20' – this does not work as there is f.e. 6 in the wordpress settings. So the question is how to overwrite those settings temporarily or to find any other solution that works without corresponding to the max-posts-per-page settings in wordpress.

        • WPBeginner Support

          With your theme overriding the query that way, you could try adding a comma to the end of line 6 and on the next line add ‘posts_per_page’ => 20 to work on overriding your theme’s posts per page.

  2. Mewaram jat

    I want to show the list of the Latest updated Products, instead of Posts. is it possible? How?

    • WPBeginner Support

      You would want to check with your eCommerce plugin for what options they would recommend as they normally have a widget or similar option.

      管理者

  3. Aditya

    How can I list more than 5 , say 30 post, recently modified post ?

    • WPBeginner Support

      If you are using the code from this article, you would change the 5 to a 30 for that :)

      管理者

  4. Sascha

    Thank you for the instructions. That was exactly what I was looking for! Finally I can show the latest updates in my sidebar.

  5. rren

    How do you include only updated posts and exclude pages?

  6. Gwénaël

    Hi,

    It works well, but it does not respect the content permissions of the page. It turns all the content visible to anybody…

  7. Des

    Hi,

    I followed you ‘How to Create a Custom WordPress Widget’, including ‘Creating a Site-Specific WordPress Plugin’ and that works perfectly. Great tutorial as I now have the ‘Hello world’ text displaying as a sidebar.

    But this one has me completely stumped. I followed the tutorial as best I could but it just displays my ‘Hello world’ text, never any list of updated posts.

    Where in my custom plugin file do I put the function wpb_lastupdated_posts()? Where do I put the ‘add_shortcode’ and where do I put the ‘if (function_exists(wpb_lastupdated_posts)) : ‘ statement?

    Many thanks,
    Des

  8. Patrick Fortino

    Code works but displays only 1 post?

  9. Gaurav Singh

    It is not working for genesis framework,

  10. sagun khadka

    How can i keep thumbnail of post when i keep it in widget ?

  11. Aida

    Thanks much, this article saved me. Code is working perfectly….

  12. Tommy

    Installed the code as stated. When using the short code- I add it to the bottom of the post. but when view the code- it puts the information on the top of the post. weird.

    • WPBeginner Support

      @Tommy, thanks for notifying us. We have updated the code. Please use the new code and it will resolve the issue.

      管理者

    • Marceli

      Same request here. I’m interested in listing recently updated Pages + showing the last_modified date. Ideally with some excerpt or number of characters from page.

  13. jerik

    Great code, but is there anyway to get this exact same function but based on comments made by specific user (admin) and list the most recent comment made as the top of the threads in the list?

    Thanks!

  14. Alberto Aguilar

    Hi… great post…. Yet I was wondering if you could give me a hand on something: I need to take the picture and title of the last three published posts and arrange them in some kind of Gallery (Just to show the latest three published articles, Any idea if there’s a plugin for that, I assume I can use the code you just placed above, but Im not quite sure on the DB structure)

    Thanks in advance… =)

  15. Mark Devlin

    Hi, how do I add code to display the category and the user who made the update?

  16. Norberto Vargas

    The second code?

  17. Norberto Vargas

    Hello

    By the way nice article, so I have a doubt.

    Where to put this code:

    “”

    thank you

  18. Pierre Guimond

    I do not know how to change the office location address on my WordPress web site. Try as I may, I cannot reach it to change it. http://www.mastheadpa.ca I would appreciate simple and straight answer. I can do most of the upkeep but that address change eludes me and i have not seen the key in the WP information and tutorials. help.

    • WPBeginner Support

      @Pierre your office location is stored inside a widget. Inside your WordPress admin area, go to Appearance » Widgets. On your right hand column you will see a list of widgets currently in use on your site. Look for Footer Widget Area and there you will see Get in Touch widget which you can edit and save your changes.

      管理者

  19. Steve

    Hi, love this article but I don’t quite get what is meant to be updated when you mention ‘use it like this:
    1

    Which file is this?

    Steve

    • WPBeginner Support

      Some users might want to display last updated posts into different templates of their WordPress themes. Those users can use this code to add it. Other users can use the shortcode to add it in their posts, pages, and widgets.

      管理者

  20. erricgunawan

    Instead of using $counter for your loop, why don’t you just use the 'posts_per_page' attribute on the WP_Query args ?

    Mine goes like this:

    $lastupdated_args = array(
    ‘orderby’ => ‘modified’,
    ‘ignore_sticky_posts’ => 1,
    ‘posts_per_page’ => 5
    );

    Also, when I try the above code, it only give me one last modified post (not five as it should be).
    Wonder why …

  21. Mary

    I love your articles but this one is way over my head. Are there any plugins for this? :)

    Sorry but I dont know the “innards” of the website and have broken my site when I tried a few things.

    It is a great idea though.Thanks for all you great work. Mary

    • Rudd

      The code above is actually a ‘plugin’. Simply copy and paste the first code in functionality plugin. Then, there are two ways to display the list of posts, either using template tag or the easiest, using [lastupdated-posts] shortcode.

      • Tommy

        yes. but why does it add the content above the post wen using it as a short code?

        • tommy

          I want the content- then the shortcode info.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。