如何在Wordpress中的单个.php添加侧边栏



我在单.php添加侧边栏时遇到了问题。我已经包括了

<?php get_sidebar(); ?>

但它似乎出现在下面,内容(博客文章)仍然在整个页面的中间。我试图查看之前的所有论坛,但没有一个帮助我解决这个问题。

这是我的单曲.php

<?php
/**
 * The template for displaying all single posts.
 *
 * @package Tesseract
*/
get_header(); ?>
<div id="primary" class="full-width-page">
    <main id="main" class="site-main" role="main">
    <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', 'single' ); ?>
        <?php tesseract_post_nav(); ?>
        <?php
            // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;
        ?>
    <?php comments_template(); ?>
    <?php endwhile; // end of the loop. ?>
    </main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

发生这种情况的最合乎逻辑的原因是没有足够的空间让主要内容和侧边栏彼此相邻显示。检查样式表中部分的宽度,并对样式进行必要的更改。

首先,您在后台创建侧边栏,然后在所需的位置调用该侧边栏。以下是调用侧边栏的代码

<ul id="sidebar">
<?php dynamic_sidebar( 'right-sidebar' ); ?>

使用以下链接了解有关如何创建侧边栏的更多信息https://codex.wordpress.org/Function_Reference/register_sidebar

最新更新