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

时间:2015-06-20 07:34:30

标签: wordpress

我在single.php添加侧边栏时遇到问题。我已经加入了

<?php get_sidebar(); ?>

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

这是我的single.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(); ?>

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

首先,您在管理员中创建侧边栏,然后在您想要的位置调用该侧边栏。以下是调用侧边栏的代码

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

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

相关问题