简体   繁体   English

具有博客页面结构的Wordpress网站

[英]Wordpress website with blog page structure

I've built a website (locally) that works just fine and, I've written the home page content in the Index page as I'm accustomed to and, different templates (page1.php, page2.php) for pages that required different layout for the 'About' and 'Contact' pages etc. Since deciding to add a blog though it has me stumped. 我已经建立了一个工作正常的网站(本地),并且按照我的习惯在“索引”页面上写了首页内容,并为需要的页面使用了不同的模板(page1.php,page2.php)关于“关于”和“联系”页面等的不同布局。自从决定添加博客以来,尽管我很困惑。 I've written a blog page and it looks just fine but when I try to view a post I'm just directed back to index.php. 我已经写了一个博客页面,看起来还不错,但是当我尝试查看帖子时,我将直接回到index.php。 I know it's down to the structure but it's confusing. 我知道这取决于结构,但令人困惑。 An index page is mandatory, and you should probably have a front-page.php too. 索引页是强制性的,您可能还应该有一个front-page.php。 If that's the case..which one should I write my home page on? 如果是这样的话..我应该在哪个页面上写我的主页? Index page doesn't show in the reading list and choosing "front page' as a static page works but still the blog links go back to index. If I was to put the content from the index page into front-page.php, what would I have in the index page? 索引页未显示在阅读列表中,而是选择“首页”作为静态页面有效,但博客链接仍返回索引。如果我将索引页中的内容放入front-page.php中,该怎么办?我将在索引页面中吗?

Although the Wordpress docs are good I can't really find anything to suggest which way round all this stuff would be. 尽管Wordpress文档很好,但是我真的找不到任何东西可以暗示所有这些东西的方向。

Your issue is that WordPress by default uses the index.php file for the blog archive (as well as other archives, etc.) and you need to use front-page.php for a dedicated home page with your custom content. 您的问题是,WordPress默认情况下将index.php文件用于博客存档(以及其他存档等),并且您需要将front-page.php用于具有自定义内容的专用主页。

Read https://developer.wordpress.org/themes/basics/template-hierarchy/ on how to construct a standard WordPress theme with template files that follow a standard hierarchy. 阅读https://developer.wordpress.org/themes/basics/template-hierarchy/ ,了解如何使用遵循标准层次结构的模板文件构建标准WordPress主题。

The front-page.php template file is used to render your site's front page, whether the front page displays the blog posts index (mentioned above) or a static page. 无论首页显示博客文章索引(如上所述)还是静态页面,front-page.php模板文件均用于呈现网站的首页。 The front page template takes precedence over the blog posts index (home.php) template. 主页模板优先于博客文章索引(home.php)模板。 If the front-page.php file does not exist, WordPress will either use the home.php or page.php files depending on the setup in Settings → Reading. 如果front-page.php文件不存在,WordPress将根据设置→阅读中的设置使用home.php或page.php文件。 If neither of those files exist, it will use the index.php file. 如果这些文件都不存在,它将使用index.php文件。

Duplicate index.php and call it front-page.php . 复制index.php并将其命名为front-page.php Edit index.php to be a basic template with a standard loop (and none of your home page content) so that it can function as a blog template that displays the_excerpt or the_content , something like this: index.php编辑为具有标准循环(并且没有主页内容)的​​基本模板,以便它可以用作显示the_excerptthe_content的博客模板,如下所示:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
<?php endwhile; else: ?>
    <?php _e( 'Sorry, no posts matched your criteria.', 'textdomain' ); ?>
<?php endif; ?>

See https://developer.wordpress.org/themes/basics/the-loop/ 参见https://developer.wordpress.org/themes/basics/the-loop/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM