在静态页面上显示博客文章
我对 WordPress 比较陌生,有一个问题。我创建了自己的主题,一切似乎都运行良好。但是,我有一个问题。我想在主页以外的页面上创建我的博客页面(包含所有帖子)。因此,在我的主题文件夹中,我创建了一个名为 blog.php 的页面模板:
<?php
/*
Template Name: blog
*/
?>
<?php get_header(); ?>
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
<?php get_footer(); ?>
然后,我还在仪表板的“页面”部分中在 WordPress 中创建了一个名为“blog”的页面。然后我将其模板分配给上面的“博客”模板。但问题是,该代码无法正常工作。它没有向我显示帖子的标题、评论等,而是显示一些其他信息。另一方面,如果我只是将其复制
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
到我的索引页,它就可以正常工作。那么,如何在主页以外的页面上显示我的所有帖子信息呢?
I am rather new to Wordpress and have a question. I have created my own theme, which all seems to work fine. But, I am having one issue. I want to create my blog page (with all the posts) on a page other than my home page. So, in my theme folder, I created a page template called blog.php:
<?php
/*
Template Name: blog
*/
?>
<?php get_header(); ?>
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
<?php get_footer(); ?>
Then, I created a page in wordpress called "blog" as well, in the "pages" section in the dashboard. I then assigned its template to the above "blog" template. The problem is, though, that the code does not work as it should. Instead of showing me the titles, comments, etc of the posts, it displays some other info. On the other hand, if i just copy this:
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
to my index page, it works fine. So, how do I display all my post info on a page other than the home page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想为您提供一个更简单的循环作为第二个选择。如果您使用此选项并将阅读设置设置为特定博客页面,则效果很好:
I wanted to provide you with a simpler loop as a second option. If you use this and set Reading settings to the specific blog page this works well:
你可以做这样的事情怎么样:
blog-template.php:
layout-page-blog.php:
这可以全部在一个文件中,或者你可以像我写的那样分成两部分使用它。
编辑:
抱歉,我已将其设置为也从帖子中抓取图像。我认为这是您需要的功能代码:
How about you do something like this:
blog-template.php:
layout-page-blog.php:
This could all be in one file, or you can use it in two pieces as I have written it.
EDIT:
Sorry I have it set to also grab the images from the post. I think this is the functions code you need: