[英]WordPress One page site (page on front-page)
我正在从头开始设计主题。 这是一个一页网站,我的CMS是WordPress。 我的文件夹结构是:
我可以将我的所有页面都显示在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中的部分?
谢谢
您可以将自定义类添加到特定的页面ID,例如:
add_filter('body_class','your_body_class'); 函数your_body_class($ classes){if(is_page(xxx))$ classes [] ='new-class'; 返回$ classs; }
您可以使用此插件自定义主体类
我做到了这一点(在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(); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.