Php 单页可湿性粉剂主题

Php 单页可湿性粉剂主题,php,wordpress,Php,Wordpress,所以我正在构建一个WP单页主题,我希望每个页面都显示在我的静态首页上。我希望用户能够在仪表板中添加/编辑页面内容,而不是标记。当我查看页面模板时,\u content()会按照广告的方式工作,但当我在静态首页上需要页面模板时,其他所有内容都会正常显示,但\u content()为空。有什么想法吗??谢谢 work.php文件 // Work Template Page -- the_content() works perfectly <!-- works --> <se

所以我正在构建一个WP单页主题,我希望每个页面都显示在我的静态首页上。我希望用户能够在仪表板中添加/编辑页面内容,而不是标记。当我查看页面模板时,\u content()会按照广告的方式工作,但当我在静态首页上需要页面模板时,其他所有内容都会正常显示,但\u content()为空。有什么想法吗??谢谢

work.php文件

//  Work Template Page -- the_content() works perfectly 


<!-- works -->
<section id="works">

    <!-- container -->
    <div class="container">
        <!-- row -->
        <div class="row">

            <!-- head -->
            <div class="head big wow bounceIn">
                <h3>Our
                    <span class="blue">Works</span>
                </h3>
                <div class="head-break-line">
                    <span class="head-line-blue"></span>
                </div>

                <?php if ( have_posts() ) : while( have_posts() ) : the_post(); ?>
                <h6 class="subtext"><?php the_content(); ?></h6>
                <?php endwhile; endif; ?>

            </div>
//工作模板页--u content()工作正常
我们的
作品
front-page.php文件

//  Static Front-Page  --  every thing works, but the_content() is blank on this page

<?php require('work.php'); ?> 
//静态首页——一切正常,但此页上的内容()为空

您需要
页面,但您已经关闭了向您提供帖子的循环。请参见此处->

<?php endwhile; endif; ?>

然后你表演

<?php require('work.php'); ?> 

这是行不通的。您需要通过执行以下操作再次执行循环:

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


从您的
work.php
文件中。

我已经这样做了。我的解决方案使用一个名为“长页面”的专门页面模板。默认情况下,该页面为空,但我有一组“内容模板”,可以附加到页面上

所以这里有一个条件:在“长页面”上,我循环遍历所有子页面。如果子页面使用“内容模板”,则会显示它

这是我的长页:

<?php 
/**
 * Template Name: Long Page
 */

define("IN_LONG_PAGE", true);
$_longpage_elements = array();

get_header(); 
?>

<div class="long_page_wrapper">
    <?php
    // Build the query for child pages
    $args = array(
        'post_parent'   => get_the_ID(),
        'post_type'     => 'page',
        'orderby'       => 'menu_order',
        'order'         => 'ASC',
    );
    $query = new WP_Query( $args );
    if($query->have_posts()): while ( $query->have_posts() ) : $query->the_post();
        // Let's see, if the child pages are actually content pages


        $page_template = get_post_meta($post->ID, "_wp_page_template", true);
        if(preg_match("#(content-templates/ct-)#i", $page_template)){
            $_longpage_elements[] = $post;
        }

    endwhile; endif;

    $query->rewind_posts();

    $num = 0;
    if($query->have_posts()): while ( $query->have_posts() ) : $query->the_post();
        // We will load the custom templates now


        if(in_array($post, $_longpage_elements)){
            $page_template = get_post_meta($post->ID, "_wp_page_template", true);
            $current_index = array_search($post, $_longpage_elements);
            include(trailingslashit(WP_THEME_PATH).$page_template); 
            $num++;
        }

    endwhile; endif;
    ?>
</div>

<?php
    get_footer();
?>


忍受我…我想出了一个简单的方法有一个可湿性粉剂一页的主题。不确定这是否是最佳实践,但这正是我想要的,而且非常容易理解。顺便说一句,我正在将一个html站点转换为一个主题…之前忘了提到这一点

所以这里是这样的…我要求每个页面在我的头版上单独出现,而不是在每个页面上循环出现。我这样做是为了将每个页面放置在我想要的位置,并自定义导航菜单:

<?php require('services.php'); ?>
<?php require('work.php'); ?>
<?php require('pricing.php'); ?>
<?php require('team.php'); ?>
<?php require('blog-page.php'); ?>
<?php require('contact.php'); ?>

然后,在每个页面(services.php、work.php等)中,我使用了WP_查询:

<?php $your_query = new WP_Query( 'pagename=work' ); ?>
<?php while ( $your_query->have_posts() ) : $your_query->the_post(); ?>

  <?php 
     //  I place all of my static page content below this line
     //  This allows me to use the_title() and the_content() functions  ?>

     <!-- head -->
     <div class="head big wow bounceIn">
        <h3>Our
            <span class="blue"><?php the_title(); ?></span>
        </h3>
        <div class="head-break-line">
           <span class="head-line-blue"></span>
        </div>
           <h6 class="subtext"><?php the_content(); ?></h6>
      </div>
      <!-- .head -->

<?php 
    //  more static content here
?>

我们的
然后,我重置postdata并添加一条条件语句,以便在有人以某种方式单独查看页面时显示页脚:

<?php endwhile; 
  // reset post data (important!)
  wp_reset_postdata(); ?>

<?php
    if ( is_page( 'work' )  ) {    
        // the page is "work" then, 
        get_footer();
    } else { 
        // don't get footer            
    }   
?>   


你确定这个页面有任何内容吗?您可以尝试使用:
输出当前帖子,以查看是否在此时将范围设置为您的帖子。谢谢,我昨天误解了您。你是对的。这个职位不在范围之内。由于我将front-page.php用作我的静态文件,而将home.php用作我的帖子,因此当需要将work.php文件添加到我的front-page.php时,我的post变量设置为“home”。显然,我还有很多事情要学。如何更改范围以匹配work.php文件中的帖子?谢谢谢谢,但是循环是在work.php文件中执行的。当访问工作页面时,它可以完美地工作,但是如果我需要它,它的内容在我的首页上是空白的。我希望我说的有道理。谢谢你的帮助,谢谢!我以前见过这种类型的工作。我在想,如果我能找到自己的工作方式,那就容易多了。就是不能让它为我工作!我可能会放弃我的项目,重新开始,做或多或少和你一样的事情。我喜欢这种方法的可扩展性。如果您需要一个模板,但还没有,那么您基本上可以添加一个页面模板。我总是尝试“尽可能标准地”实现东西,这是我能想到的最标准的方式。在代码标准和WP UX方面。
<?php endwhile; 
  // reset post data (important!)
  wp_reset_postdata(); ?>

<?php
    if ( is_page( 'work' )  ) {    
        // the page is "work" then, 
        get_footer();
    } else { 
        // don't get footer            
    }   
?>