我在wordpress 3.6.1上使用博客生活主题,我的模板如下所示:
<?php
/*
Template Name: Template One
*/
?>
<?php
/**
* A custom template file.
* @package WPLOOK
* @subpackage BlogoLife
* @since BlogoLife 1.0
*/
get_header();
$hasSidebar = "";
$sidebar = get_post_meta($post->ID,\'wpl_enable_sidebar\',true);
get_template_part(\'content\', \'page\' ) ;
//get_template_part(\'inc\', \'indexloop\' ) ;
if($sidebar=="false" ) {
echo \'<div class="clear"></div>\';
} else {
get_sidebar(one);
}
get_footer(); ?>
内容页。php如下所示:
<?php
/**
* The default template for displaying content
*
* @package wplook
* @subpackage BlogoLife
* @since BlogoLife 1.0
*/
?>
<div class="primary">
<div id="content">
<?php wplook_doctitle(); ?>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col1 fleft">
<div class="postformat">
<div class="format-icon"></div>
<div class="left-corner"></div>
</div>
</div>
<div class="col2 fright">
<header class="entry-header">
<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'wplook\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1></header>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( \'before\' => \'<div class="clear"></div><div class="page-link"><span>\' . __( \'Pages:\', \'wplook\' ) . \'</span>\', \'after\' => \'</div>\' ) ); ?>
<!-- .entry-content -->
<div class="clear"></div>
<div class="entry-utility">
<?php if ( the_category ( \'\', \', \' ) ) { ?>
<div class="category">
<b><?php _e(\'Category:\', \'wplook\'); ?></b>
<?php the_category(\', \') ?>
<div class="end"></div>
</div>
<?php } ?>
<?php if ( get_the_tag_list( \'\', \', \' ) ) { ?>
<div class="tag">
<b><?php _e(\'Tag:\', \'wplook\'); ?></b>
<?php echo get_the_tag_list(\'\',\', \',\'\'); ?>
<div class="end"></div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
</div><!-- .entry-content -->
<footer class="entry-meta">
<div class="date-i fleft"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'wplook\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="nofollow"><?php wplook_get_date_time();?></a></div>
<?php if ( comments_open() ) : ?>
<div class="comment-i fleft"><?php comments_popup_link(__(\'No comments\', \'wplook\'), __(\'1 comment\', \'wplook\'), __(\'% comments\', \'wplook\'), \'comments-link\', __(\'Comments off\', \'wplook\')); ?></div>
<?php endif; ?>
<div class="author-i fleft"><?php wplook_get_author();?></div>
<?php edit_post_link( __( \'Edit\', \'wplook\' ), \'<div class="edit-i fright">\', \'</div>\' ); ?>
<div class="clear"></div>
</footer>
</div>
<div class="clear"></div>
</article>
<?php comments_template( \'\', true ); ?>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
但什么都没有发生。我的索引。使用的php
get_template(\'inc\' \'indexloop\' ) ;
它显示了所有条目,但当我在自定义模板上使用此函数时,也没有显示任何内容。
顺便说一句,这是我的未修改索引。php,修改后的工作原理相同,只有一些编辑:
<?php
/**
* The main template file.
*
* @package WPLOOK
* @subpackage BlogoLife
* @since BlogoLife 1.0
*/
get_header();
get_template_part(\'inc\', \'indexloop\' ) ;
get_sidebar();
get_footer(); ?>
最合适的回答,由SO网友:cybmeta 整理而成
使用此代码:
get_template_part(\'content\', \'page\' );
Wordpress将尝试加载一个名为
content-page.php
如果此文件不存在,则将尝试加载
content.php
. 您的主题似乎包含该文件
content-page.php
, 所以如果你想加载
content.php
您应该使用:
get_template_part(\'content\');
编辑:您已使用编辑问题并删除此问题的代码
get_template_part()
. 我认为最好保留问题中的原始代码,并且在任何情况下,添加带有新注释的新代码。
关于内容模板不显示任何博客条目的原因:如果您在发布时使用的模板是“页面”的模板(作为名称content-page.php
还建议使用名称page-one.php
如果你说它不起作用),你需要运行一些代码来获取你想要显示的帖子,然后再开始循环;Wordpress所做的查询只是获取实际“页面”所需的查询。一个简单的例子:
<div class="primary">
<div id="content">
<?php wplook_doctitle(); ?>
<?php
// See the docu for more arguments: http://codex.wordpress.org/Class_Reference/WP_Query
$the_query = new WP_Query(\'showposts=5\' . \'&paged=\'.$paged);
if ( $the_query->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col1 fleft">
<div class="postformat">
<div class="format-icon"></div>
<div class="left-corner"></div>
</div>
</div>
<div class="col2 fright">
<header class="entry-header">
<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'wplook\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( \'before\' => \'<div class="clear"></div><div class="page-link"><span>\' . __( \'Pages:\', \'wplook\' ) . \'</span>\', \'after\' => \'</div>\' ) ); ?>
<!-- .entry-content -->
<div class="clear"></div>
<div class="entry-utility">
<?php if ( the_category ( \'\', \', \' ) ) { ?>
<div class="category">
<b><?php _e(\'Category:\', \'wplook\'); ?></b>
<?php the_category(\', \') ?>
<div class="end"></div>
</div>
<?php } ?>
<?php if ( get_the_tag_list( \'\', \', \' ) ) { ?>
<div class="tag">
<b><?php _e(\'Tag:\', \'wplook\'); ?></b>
<?php echo get_the_tag_list(\'\',\', \',\'\'); ?>
<div class="end"></div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
</div><!-- .entry-content -->
<footer class="entry-meta">
<div class="date-i fleft"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'wplook\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="nofollow"><?php wplook_get_date_time();?></a></div>
<?php if ( comments_open() ) : ?>
<div class="comment-i fleft"><?php comments_popup_link(__(\'No comments\', \'wplook\'), __(\'1 comment\', \'wplook\'), __(\'% comments\', \'wplook\'), \'comments-link\', __(\'Comments off\', \'wplook\')); ?></div>
<?php endif; ?>
<div class="author-i fleft"><?php wplook_get_author();?></div>
<?php edit_post_link( __( \'Edit\', \'wplook\' ), \'<div class="edit-i fright">\', \'</div>\' ); ?>
<div class="clear"></div>
</footer>
</div>
<div class="clear"></div>
</article>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- #content -->
</div><!-- #primary -->