Wordpress 显示所有帖子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12844507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:02:38  来源:igfitidea点击:

Wordpress Display All Posts

wordpressblogsposts

提问by user982853

THis may be really easy but i have searched and search and cant find anything. What is the default blog page?

这可能真的很容易,但我已经搜索并搜索过,但找不到任何东西。什么是默认博客页面?

I am trying to find the page that will display excerpts of all my blog posts regardless of category or tags. I know that I can do www.xyz.com/category/widgets to get a list of all the posts in that category. What I am trying to do is just list all my blog posts without any filter.

我试图找到一个页面,该页面将显示我所有博客文章的摘录,而不管类别或标签如何。我知道我可以通过 www.xyz.com/category/widgets 获取该类别中所有帖子的列表。我想要做的只是列出我所有的博客文章,没有任何过滤器。

Is there a default page in wordpress to achieve this? Thank you.

wordpress 中是否有默认页面可以实现此目的?谢谢你。

回答by Tomá? Kapler

If you want it for all categories/tags/fron_page, there is very quick sollution - go to /wp-admin/options-reading.php and set the number of posts to -1 - it is not normally possible as the input got min=1, but you can change it easily with e.g. browser developer console.

如果你想要所有类别/标签/fron_page,有一个非常快速的解决方案 - 转到 /wp-admin/options-reading.php 并将帖子数设置为 -1 - 通常是不可能的,因为输入得到 min =1,但您可以使用例如浏览器开发者控制台轻松更改它。

If you want just one page with all posts, you can simply create template or shortcode, with http://codex.wordpress.org/Template_Tags/get_postsand numberposts set to -1 and show what you need, e.g.

如果您只想要一个包含所有帖子的页面,您可以简单地创建模板或简码,将http://codex.wordpress.org/Template_Tags/get_posts和 numberposts 设置为 -1 并显示您需要的内容,例如

<?php
$args = array( 'numberposts' => -1); 
$posts= get_posts( $args );
if ($posts) {
    foreach ( $posts as $post ) {
        setup_postdata($post);
        the_title();
        the_excerpt();
    }
}
?>

回答by Simon East

For others who might be Googling this... If you have replaced the front page of your site with a staticpage, but still want your list of posts to appear under a separate link, you need to:

对于可能在谷歌上搜索此内容的其他人...如果您已用静态页面替换了您网站的首页,但仍希望您的帖子列表显示在单独的链接下,您需要:

  1. Create an empty page (and specify any URL/slug you like)
  2. Under Settings > Reading, choose this new page as your "Posts page"
  1. 创建一个空页面(并指定您喜欢的任何 URL/slug)
  2. Settings > Reading 下,选择这个新页面作为您的“帖子页面”

Now when you click the link to this page in your menu, it should list all your recent posts (no messing with code required).

现在,当您单击菜单中指向此页面的链接时,它应该会列出您最近发布的所有帖子(无需弄乱代码)。

(Disclaimer: I posted this same answer to a similar question here.)

(免责声明:我在这里发布了对类似问题的相同答案。)

回答by Xhynk

This all depends on your theme, you'd need a blog.php, page-blog.php, archive.php (you get the idea).

这一切都取决于你的主题,你需要一个 blog.php、page-blog.php、archive.php(你懂的)。

It will be a php page that's got a basic WP_Query()with no definition of category or anything.

这将是一个 php 页面,它有一个基本WP_Query()的没有类别或任何定义的页面。

You'd be able to define this either in:

您可以在以下任一方式中定义:

  1. Settings > Reading --- Blog Page
  2. Theme Options --- (something like) Blog Categories [pick all]
  3. define it for all posts in the PHP file itself
  1. 设置 > 阅读 --- 博客页面
  2. 主题选项 ---(类似)博客类别 [选择全部]
  3. 为 PHP 文件本身中的所有帖子定义它

hopefully this helps, sorry there's not a "do that 'here'" answer for you :/

希望这会有所帮助,抱歉,没有“在这里做那个”的答案:/

回答by Aveesh

Thx for this - I also found another way ...

为此,我还找到了另一种方法......

In your theme's files - look for blog-page.php

在您的主题文件中 - 查找 blog-page.php

If it is not there - copy blog.php as blog-page.php

如果不存在 - 将 blog.php 复制为 blog-page.php

In blog-page.php - change description to be Blog (Page). this causes the template to be listed as Blog (Page) where you can use the template your wordpress page uses.

在 blog-page.php - 将描述更改为博客(页面)。这会导致模板被列为博客(页面),您可以在其中使用您的 wordpress 页面使用的模板。

Customize your sidebar with categories and recent posts widgets....

使用类别和最近的帖子小部件自定义您的侧边栏....