我已经更新了我的wordpress,现在我的wordpress单个帖子没有显示。标题和帖子标题显示但帖子标题和侧边栏丢失。
当我切换到其他主题时,一切正常,但是我的主题有问题。我试图手动重新安装主题的sigle.php,但没有任何改变。我尝试更改永久链接结构,删除所有非活动插件并关闭和打开所有活动插件,但仍然没有任何更改。
我正在使用Gabfire的Sharp Magazine主题。这是一个例子:http://www.turizamiputovanja.com/nis-dobija-novi-hotel-u-centru-grada/。
这是我的single.php
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
/* post template defined on custom fields? */
$post_layout = get_post_meta($post->ID, 'gabfire_post_template', true);
/* Any subtitle entered to post? */
$subtitle = get_post_meta($post->ID, 'subtitle', true);
?>
<?php /* Post lead */ ?>
<section class="row">
<div class="col-md-12">
<div class="post-lead">
<p class="post-category"><?php the_category(' · '); ?></p>
<h1 class="post-title"><?php the_title(); ?></h1>
<p class="post-datecomment">
<?php
$authorlink = '<a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'. get_the_author() . '</a>';
printf(esc_attr__('%2$s Autor: %1$s','gabfire'), $authorlink, get_the_date());
?>
<?php
/* get the number of comments */
$num_comments = get_comments_number();
if ( comments_open() ){
if($num_comments == 0){ $comments = __('Nema komentara', 'gabfire'); }
elseif($num_comments > 1){ $comments = $num_comments. __(' Komentara', 'gabfire'); }
else{ $comments = __('1 komentar', 'gabfire'); }
}
echo '<span class="commentnr">' . $comments . '</span>';
?>
</p>
<?php
if (($subtitle != '') && (($post_layout == 'bigpicture') or ($post_layout == 'fullwidth'))) {
echo "<p class='subtitle postlead_subtitle'>$subtitle</p>"; }
?>
</div>
</div>
</section>
<?php
/* Call user defined post template */
if ($post_layout == 'bigpicture') {
get_template_part( 'single', 'bigpicture' );
} elseif ($post_layout == 'fullwidth') {
get_template_part( 'single', 'fullwidth' );
} elseif ($post_layout == 'leftsidebar') {
get_template_part( 'single', 'leftsidebar' );
} else {
get_template_part( 'single', 'default' );
}
?>
<?php endwhile; else : endif; ?>
<?php get_footer(); ?>
我在这里有所有类似的问题和答案,但似乎没有一个对我有帮助。谢谢!
答案 0 :(得分:0)
the_content()应该在循环中,因为这实际上是您帖子的内容。
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
/* post template defined on custom fields? */
$post_layout = get_post_meta($post->ID, 'gabfire_post_template', true);
/* Any subtitle entered to post? */
$subtitle = get_post_meta($post->ID, 'subtitle', true);
?>
<?php /* Post lead */ ?>
<section class="row">
<div class="col-md-12">
<div class="post-lead">
<p class="post-category"><?php the_category(' · '); ?></p>
<h1 class="post-title"><?php the_title(); ?></h1>
<p class="post-datecomment">
<?php
$authorlink = '<a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'. get_the_author() . '</a>';
printf(esc_attr__('%2$s Autor: %1$s','gabfire'), $authorlink, get_the_date());
?>
<?php
/* get the number of comments */
$num_comments = get_comments_number();
if ( comments_open() ){
if($num_comments == 0){ $comments = __('Nema komentara', 'gabfire'); }
elseif($num_comments > 1){ $comments = $num_comments. __(' Komentara', 'gabfire'); }
else{ $comments = __('1 komentar', 'gabfire'); }
}
echo '<span class="commentnr">' . $comments . '</span>';
?>
</p>
<?php
if (($subtitle != '') && (($post_layout == 'bigpicture') or ($post_layout == 'fullwidth'))) {
echo "<p class='subtitle postlead_subtitle'>$subtitle</p>"; }
?>
</div>
</div>
</section>
<div class="row">
<div class="col-md-8">
<?php the_content(); ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php
/* Call user defined post template */
/*if ($post_layout == 'bigpicture') {
get_template_part( 'single', 'bigpicture' );
} elseif ($post_layout == 'fullwidth') {
get_template_part( 'single', 'fullwidth' );
} elseif ($post_layout == 'leftsidebar') {
get_template_part( 'single', 'leftsidebar' );
} else {
get_template_part( 'single', 'default' );
} */
?>
<?php endwhile; else : endif; ?>
<?php get_footer(); ?>
the_template_part 正在加载 single-default.php ,这很奇怪,因为 single-default.php 包含另一个循环?这个文件结构不合适,请看看二十九主题:
<?php
/**
* The template for displaying all single posts and attachments
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the single post content template.
get_template_part( 'template-parts/content', 'single' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
if ( is_singular( 'attachment' ) ) {
// Parent post navigation.
the_post_navigation( array(
'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
) );
} elseif ( is_singular( 'post' ) ) {
// Previous/next post navigation.
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
查看 get_template_part(&#39; template-parts / content&#39;,&#39; single&#39;); 他们将内容内容切断到其他文件模板 - 零件/内容单。 fe在很多方面都比较好。管理,版本控制。