单个 post 内容未显示
Single post content not showing up
我更新了我的 wordpress,但现在我的 wordpress 单曲 post 没有显示。 Header 和 post 标题显示,但 post 标题和侧边栏缺失。
当我切换到其他主题时,一切正常,但我的主题有问题。我尝试手动重新安装 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(); ?>
我把所有类似的问题和答案都标红了,但是 none 似乎对我有帮助。谢谢!
the_content() 应该在循环内,因为这实际上是 post.
的内容
<?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 包含另一个循环?这个文件结构不合适,看看twentysixteen theme:
<?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( 'template-parts/content', 'single' ); 他们把内容内容截断到其他文件 template-parts/content-single。它在很多方面都更好。管理,版本控制。
我更新了我的 wordpress,但现在我的 wordpress 单曲 post 没有显示。 Header 和 post 标题显示,但 post 标题和侧边栏缺失。
当我切换到其他主题时,一切正常,但我的主题有问题。我尝试手动重新安装 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(); ?>
我把所有类似的问题和答案都标红了,但是 none 似乎对我有帮助。谢谢!
the_content() 应该在循环内,因为这实际上是 post.
的内容<?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 包含另一个循环?这个文件结构不合适,看看twentysixteen theme:
<?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( 'template-parts/content', 'single' ); 他们把内容内容截断到其他文件 template-parts/content-single。它在很多方面都更好。管理,版本控制。