【问题标题】:WordPress One page site (page on front-page)WordPress 单页网站(首页上的页面)
【发布时间】:2019-02-25 13:14:59
【问题描述】:

我正在从头开始设计一个主题。这是一个单页网站,我的 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 中的部分?

谢谢

【问题讨论】:

  • 你是指哪些类?身体课?这在很大程度上取决于您的 CSS 的组织方式。
  • 我的页面中的类-xxx.php。

标签: php wordpress


【解决方案1】:
  1. 您可以将自定义类添加到特定的页面 id,例如:

    add_filter('body_class', 'your_body_class'); 功能 your_body_class($classes) { if (is_page(xxx)) $classes[] = '新班级'; 返回$类; }

  2. 你可以使用这个插件Custom Body Class

【讨论】:

  • 它在我的页面中添加了类,但是当页面成为我的 front-page.php 上的部分时,我遇到了同样的问题。
  • 它们如何成为部分?你在哪里嵌入它们?
  • 我在第一篇文章中发布了循环。此循环位于我的 front-page.php 上,并将所有其他页面显示为我的 One page 站点的部分。
【解决方案2】:

我是这样做的(在 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(); ?>

看起来可行,我的三个页面及其类分为三个部分。但是现在,我没有内容了。

我的页面-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(); ?>

【讨论】:

  • 问题已解决。而不是我使用的循环: 。就是这样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
  • 1970-01-01
  • 2011-10-07
  • 1970-01-01
  • 2018-02-20
相关资源
最近更新 更多