首页 > 解决方案 > 侧边栏出现在自定义帖子页面上而不被调用

问题描述

我正在为一个图形组合网站创建一个 Wordpress 主题,并且我正在使用 sidebar.php 作为索引页面上的一个不打算出现在其他页面上的英雄图像。虽然这适用于所有静态内页,但我有两个自定义帖子类别,并且侧边栏部分已开始出现在这些帖子上方。

我应该注意到这并不总是一个问题,并且在从事其他工作时无缘无故地开始出现。

在 index.php 上,侧边栏的调用方式如下:

<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; ?>
<nav>
<ul class="pager">
<li><?php next_posts_link( 'Previous' ); ?></li>
<li><?php previous_posts_link( 'Next' ); ?></li>
</ul>
</nav>
<?php endif;?>
<?php get_footer(); ?>

而page.php类似但缺少调用侧边栏的php行,如下:

<?php get_header(); ?>
<div class="row">
<div class="col-sm-12">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;?>
</div> <!-- /.col -->
</div> <!-- /.row -->
<?php get_footer(); ?>

page-fine-art.php 也缺少该 php 行,如下所示:

<div class="row">
<div class="col-sm-12">
<?php
$args =  array(
'post_type' => 'fine-art',
'orderby' => 'menu_order',
'order' => 'ASC'
);
$custom_query = new WP_Query( $args );
while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div class="blog-post">
<h2 class="blog-post-title"><a href="<?php the_permalink(); ?>"><?      php the_title(); ?></a></h2>
<p class="blog-post-meta"><?php the_date(); ?> by <a href="#"><?php    the_author(); ?></a></p>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
</div> <!-- /.col -->
</div> <!-- /.row -->
<?php get_footer(); ?>

为“美术”创建自定义帖子的功能是:

function create_my_custom_posts() {
register_post_type( 'fine-art',
array(
'labels' => array(
'name' => __( 'Fine Art' ),
'singular_name' => __( 'Fine Art' ),
),
'public' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'thumbnail',
'custom-fields'
)
));

我看不到在最后一个示例中调用了 sidebar.php 的位置,或者它可能来自哪里。

标签: phpwordpress

解决方案


推荐阅读