严重的php get_template_part()Wordpress问题-轻松修复?
我需要从其他人那里获得一些严肃的Wordpress专业知识。我正在构建自定义主题,阅读了严重的php get_template_part()Wordpress问题-轻松修复?,php,html,wordpress,function,methods,Php,Html,Wordpress,Function,Methods,我需要从其他人那里获得一些严肃的Wordpress专业知识。我正在构建自定义主题,阅读了get\u template\u part()方法,并决定这将有助于清理和组织我的代码。我在几个地方更新了我的主题以使用此方法,现在该网站已完全崩溃…没有任何东西将加载!!:(我非常感谢您的帮助!我将复制并粘贴下面的一些php文件。也许有更多使用此方法经验的人可以指出问题。谢谢 page.php <?php get_header(); ?> <div id="content
get\u template\u part()
方法,并决定这将有助于清理和组织我的代码。我在几个地方更新了我的主题以使用此方法,现在该网站已完全崩溃…没有任何东西将加载!!:(我非常感谢您的帮助!我将复制并粘贴下面的一些php文件。也许有更多使用此方法经验的人可以指出问题。谢谢
page.php
<?php get_header(); ?>
<div id="content" class="content">
<?php while ( have_posts() ) : the_post(); ?>
<!-- About page -->
<?php if (is_page('about')) ?>
<?php get_template_part( 'page', 'about' ); ?>
<!-- Media & Gallery page -->
<?php if (is_page('media-gallery')) ?>
<?php get_template_part( 'page', 'mediagallery' ); ?>
<?php endwhile; // end of the loop. ?>
</div> <!--/end content -->
<?php get_footer(); ?>
<div id="about">
<div class="text">
<h2 class="about"><?php echo get_the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
<div id="pic-gallery">
<?php include_once 'includes/pwaplusphp/albums.php'; ?>
</div>
<?php get_header(); ?>
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<br class="clr"/>
<?php endwhile; ?>
<?php content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h3 class="blog"><?php _e( 'Nothing Found' ); ?></h3>
</header> <!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'); ?></p>
</div> <!-- .entry-content -->
</article> <!-- #post-0 -->
<?php endif; ?>
</div> <!--/end content -->
<?php get_footer(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-date"><?php the_time(get_option('date_format')); ?></div>
<h3 class="blog"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content(); ?></div>
</div>
我一点儿也不知道我做错了什么(
编写朋友的想法?!以您的page-about.php为例,您应该在模板中这样称呼它:
<?php get_template_part( "page-about" ); ?>
模板需要位于主题目录的根目录中,以便您可以使用
“页面关于”
没有.php
,并且不必指明文件将位于的位置/目录。我以前也遇到过这种情况-我无法解释为什么,因为我仍在深入阅读文档,但当您在post循环中时,似乎无法以这种方式调用模板部分;)
在循环中的任何时候,请尝试使用以下选项:
对不起,Jeremy,但不幸的是,这不起作用。法典说正确的语法应该是
。在上面的示例中,在“page”和“about”之间加上破折号不起作用。我不知道获取模板部分()
方法。当法典提到使用$slug
,$name
时,它指的是检索模板中包含多个模板部分的指定部分。一个例子是多个主题使用的index.php。它们在一个模板中定义单个帖子、存档等。为此,您需要$slug
,$name
。我一直在单个文件上使用我的建议。确保它位于主题的根目录中,并且与get\u template\u部分中的代码同名,我上面给出的示例将插入位于站点根目录中的page-about.php中的内容。
<?php get_template_part( "page-about" ); ?>