php - WordPress 单页网站(首页上的页面)
问题描述
我正在从头开始设计一个主题。这是一个单页网站,我的 CMS 是 WordPress。我的文件夹结构是:
- 头版.php
- page-about.php
- page-work.php
- page-contact.php
我可以在 front-page.php 上将所有页面显示为部分,但我丢失了所有自定义类(和特定样式)。这是我的 front-page.php 中的循环:
<?php get_header(); ?>
<?php query_posts('post_type=page&order=ASC'); ?>
<?php
if (have_posts()):
while (have_posts()) : the_post(); ?>
<section id="page-<?php the_ID(); ?>">
<div class="container">
<h2><?php the_title(); ?></h2>
<article>
<p><?php the_content(); ?></p>
</article>
</div>
</section>
<?php endwhile;
endif; ?>
<?php get_footer(); ?>
如何将 page-xxx.php 的样式(因此,它们的类/ID)保留为我的 front-page.php 部分?
谢谢
解决方案
我这样做了(在 front-page.php 中):
<?php get_header(); ?>
<?php
$args = array(
'post_type' => 'page',
'order' => 'ASC'
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ( $query->have_posts()) {
$query->the_post();
$tn = get_page_template_slug($post_id);
$word = array("page-", ".php",' ');
$template = str_replace($word,'',$tn);
get_template_part('page', $template);
}
}
?>
<?php get_footer(); ?>
看起来它有效,我的三个页面和他们的课程分为三个部分。但现在,我没有内容。
我的 page-about.php :
<?php get_header();
/* Template Name: About */ ?>
<section id="about" class="section section-about">
<div class="container">
<h2 class="title-2"><?php the_title(); ?></h2>
<div class="col-md-6 col-lg-12"></div>
<article class="article-about">
<?php
if (have_posts()):
while (have_posts()): the_post(); ?>
<p><?php the_content(); ?></p>
<?php endwhile;
endif;
?>
</article>
</div>
</section>
<?php get_footer(); ?>
推荐阅读
- java - JSONObject 无法转换为 JSONArray Volley - Android
- c# - 以特定方式显示数据表中的数据
- markdown - 由 kramdown 呈现的 GitHub 风格的降价是否有最大数量的嵌套列表?
- javascript - 有没有办法通过用户输入连续移动 P5 中的对象?
- javascript - 如果按钮与 h1 在同一行,则按钮不起作用
- html - 如何使网格元素为其拥有的每个子元素都有一列?
- c# - EF Core 中的通用搜索实现
- cloud-foundry - 在所有 Pivotal Cloud Foundry 实例上执行 REST 调用
- python - Django 和 HTML 下拉菜单:使用选定的任一子属性填充父/子字段
- firebase - 如何使用flutter中的子值从firebase获取数据?