【问题标题】:Wordpress Custom pagesWordPress 自定义页面
【发布时间】:2016-06-16 04:14:45
【问题描述】:

我想使用函数 get_template_part() 将我所有的自定义页面加载到首页;但是每当我保存我的代码时,页面都会在首页加载所有内容,但会不断地在网站上一遍又一遍地循环内容。

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

            <?php while (have_posts()) : the_post(); ?>
                <?php get_template_part('templates/header'); ?>
                <?php get_template_part('templates/page-about'); ?>
                <?php get_template_part('templates/page-services'); ?>
                <?php get_template_part('templates/page-portfolio'); ?>
                <?php get_template_part('templates/page-contact'); ?>
                <?php get_template_part('templates/footer'); ?>
            <?php endwhile; ?>

    </main><!-- #main -->
</div><!-- #primary -->

我也要上传到githubhttps://github.com/brandonpowell/Test-Wordpress-Site/tree/master/danielschriersite

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    多次调用标头尝试删除每个模板

    你也可以在首页模板中调用

    尝试使用 wordpress 页面模板

    https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/

    <?php
    /**
     * Template Name: Front Page Template
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
    */
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
                <?php get_template_part('templates/header'); ?>
                <?php get_template_part('templates/page-about'); ?>
                <?php get_template_part('templates/page-services'); ?>
                <?php get_template_part('templates/page-portfolio'); ?>
                <?php get_template_part('templates/page-contact'); ?>
                <?php get_template_part('templates/footer'); ?>
    <?php endwhile; ?>
    

    然后你从管理仪表板更改页面模板 attr

    你也可以使用 is_front_page() 函数

    <?php if( is_front_page() ) { ?>
    
           <?php get_template_part('templates/header'); ?>
           <?php get_template_part('templates/page-about'); ?>
           <?php get_template_part('templates/page-services'); ?>
           <?php get_template_part('templates/page-portfolio'); ?>
           <?php get_template_part('templates/page-contact'); ?>
           <?php get_template_part('templates/footer'); ?>
    
    <?php } ?>
    

    【讨论】:

    • @HermanAndresFigeroa 是的,我已经将模板更改为首页作品,这里试图说的是,当他在首页没有加载所有内容时,只是不断重复自己。 gyazo.com/b51d13f7ac66cc702d2147925f19b0a7 我已经看过这个 wordpress 链接很多时间了
    • @HermanAndresFigeroa 是的,他正在调用 wordpress 后端中的每个模板。你有 Skype 添加brandonpdesigns 这样我可以更好地向你解释一下
    • 很多时候包括模板和内容,因此没有重复 the_content () 的 esta ? i.imgur.com/NDQbNDx.png
    • 尝试只留下模板的调用,get_template_part() 来检查内容是否不断重复自己
    • @HermanAndresFigeroa 离开模板的调用是什么意思,他还在学习开发 wordpress。
    猜你喜欢
    • 2019-04-07
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2014-04-23
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多