php - 侧边栏出现在自定义帖子页面上而不被调用
问题描述
我正在为一个图形组合网站创建一个 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 的位置,或者它可能来自哪里。
解决方案
推荐阅读
- python - 在列表中编辑列表的某个部分
- python - 如何在 y 轴上绘制一列(名称)并在同一 y 轴上绘制另一列的值
- kubernetes - 无法解析 Ansible Playbook 上的模块/操作“k8s_exec”
- winapi - MFC:CMFCToolbar 和 CMFCMenuBar 在 DPI 更改时变黑并失真
- android - Android中的paddingLeft和paddingStart有什么区别?
- flutter - 在颤动的 TextFormField 中,使用 double.parse 时我无法清除该值
- javascript - 在 Flask“POST”路由中发送 JSON 响应
- python - 如何解决 Flopy 中用于头表边界的此错误?
- javascript - 表单元素传单中未选择关闭层
- javascript - 连续删除特定重复的特殊字符,但每次使用正则表达式至少保留一个?