将评论区域移至内容区

时间:2016-08-08 05:46:52

标签: php css wordpress widget comments

注意:在这篇文章的底部,我刚刚添加了更新。更新中的注释可能会使原始帖子的某些部分变得多余。 最后我想在我的所有页面上都有一个评论部分。目前我只是在某些页面上激活了评论。

我在此页http://www.rosstheexplorer.com/how-to-back-up-photos-when-abroad/

上未激活评论

我确实在此页http://www.rosstheexplorer.com/blue-moutnains-and-katoomba-nsw/

上激活了评论

当我激活评论时,FB插件会从屏幕右侧移动到页面底部。我怎么能阻止这个?我改变了注释区域的宽度,并使注释区域向左浮动,但这并没有解决我的问题。我也摆脱了"明确:两者"文本并没有解决问题。我现在把"清楚了:两者都是"我的代码中的文字。

当没有评论时,小部件区域位于网站内容中。

enter image description here

当有评论时,小部件区域会被移动。我怎么能阻止这个?这会导致问题吗?

enter image description here

有人有任何建议吗?

评论区号为

`/* =Comments */

.comments-area {
margin: 24px auto 0;
border-top: 3px solid #eee;
}

.comments-title,
#respond h3 {
font-size: 1.2em;
line-height: 1.36em;
color: #999;
}
.comments-title small,
.comment-reply-title small {
float: right;
}

.comment-list,
.comment-list .children {
list-style: none;
}

.comment-list {
margin: 0;
}

.comment-list > .comment:first-of-type {
padding-top: 0;
border-top: 0;
}

.comment {
margin-top: 26px;
padding-top: 27px;
border-top: 1px solid #eee;
}

.comment-meta {
text-transform: uppercase;
}
.comment-meta a {
color: #666;
}
.comment-meta .comment-author img {
float: left;
border-radius: 50%;
}
.comment-meta .comment-author .fn {
display: block;
font-weight: normal;
margin-left: 74px;
text-transform: none;
}
.bypostauthor > article .fn:after {
content: "\f304";
font-size: 16px;
left: 3px;
position: relative;
top: -5px;
}
.comment-meta .comment-metadata {
font-size: .8125em;
font-weight: normal;
line-height: 2.09231em;
margin-bottom: 27px;
margin-left: 74px;
letter-spacing: 1px;
color: #999;
}
.comment-meta .comment-metadata a {
color: #999;
}
.comment-meta .comment-metadata a:hover {
color: #1c7c7c;
}

.comments-area .edit-link:before {
display: inline;
margin: 0 7px;
content: ' ~ ';
}

.comment-form label {
display: inline-block;
width: 109px;
}

.required {
color: #1c7c7c;
}

.comment-form-author,
.comment-form-email,
.comment-form-url,
.comment-form-comment {
position: relative;
margin: 0 0 27px;
}
.comment-form-author label,
.comment-form-email label,
.comment-form-url label,
.comment-form-comment label {
font-size: .8125em;
font-weight: normal;
line-height: 2.09231em;
position: absolute;
top: 7px;
left: 0;
padding: 7px 14px;
letter-spacing: 1px;
text-transform: uppercase;
}
.comment-form-author input,
.comment-form-email input,
.comment-form-url input,
.comment-form-comment input {
display: block;
clear: both;
width: 100%;
margin: 0 0 27px;
padding-left: 100px;
}
.comment-form-author textarea,
.comment-form-email textarea,
.comment-form-url textarea,
.comment-form-comment textarea {

width: 100%;
margin: 0 0 27px;
padding: 54px 14px 7px;
}

.says {
display: none;
}

.form-allowed-tags {
color: #999;
}

.no-comments {
font-style: italic;
margin: 27px 0;
text-align: center;
color: #999;
}

index.php代码是

<?php
/**
 * The main template file.

 *
 *
 * @package Penscratch
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">



        <?php if ( have_posts() ) : ?>

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php
                    /* Include the Post-Format-specific template for the content.
                     * If you want to override this in a child theme, then include a file
                     * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                     */
                    get_template_part( 'content', get_post_format() );
                ?>

            <?php endwhile; ?>

            <?php penscratch_paging_nav(); ?>

        <?php else : ?>

            <?php get_template_part( 'content', 'none' ); ?>

        <?php endif; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

comments.php代码是

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains both current comments
 * and the comment form.
 *
 * @package Penscratch
 */

/*
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the comments.
 */
if ( post_password_required() ) {
    return;
}
?>

<div id="comments" class="comments-area">



    <?php // You can start editing here -- including this comment! ?>

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php
                printf( _nx( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'comments title', 'penscratch' ),
                    number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
            ?>
        </h2>

        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
        <nav id="comment-nav-above" class="comment-navigation" role="navigation">
            <h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'penscratch' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( __( '< Older Comments', 'penscratch' ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( __( 'Newer Comments >', 'penscratch' ) ); ?></div>
        </nav><!-- #comment-nav-above -->
        <?php endif; // check for comment navigation ?>

        <ol class="comment-list">
            <?php
                wp_list_comments( array(
                    'style'       => 'ol',
                    'short_ping'  => true,
                    'avatar_size' => 60
                ) );
            ?>
        </ol><!-- .comment-list -->

        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
        <nav id="comment-nav-below" class="comment-navigation" role="navigation">
            <h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'penscratch' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( __( '< Older Comments', 'penscratch' ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( __( 'Newer Comments >', 'penscratch' ) ); ?></div>
        </nav><!-- #comment-nav-below -->
        <?php endif; // check for comment navigation ?>

    <?php endif; // have_comments() ?>

    <?php
        // If comments are closed and there are comments, let's leave a little note, shall we?
        if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    ?>
        <p class="no-comments"><?php _e( 'Comments are closed.', 'penscratch' ); ?></p>
    <?php endif; ?>

    <?php comment_form(); ?>



</div><!-- #comments -->

更新 - 我改变了索引的底部.php

<?php get_sidebar(); ?>

</div><!-- #primary -->

<?php get_footer(); ?>

然后我搞乱了IE开发人员工具中的评论区域。很明显,评论区域是侧栏或/和小部件区域的一部分。当我将注释区域的宽度更改为200px时,它移动到内容的右侧而不是下方。

然后使用IE开发人员工具我移动了评论区域,使其嵌套在内容区域中。然后评论区域和FB插件都出现了我希望它们出现的方式。

如何更改代码以使注释区域永久嵌套在内容区域中?

3 个答案:

答案 0 :(得分:0)

您正在使用的模板的窗口小部件区域设置在注释下方。您可能希望探索小部件区域所在的模板结构,而不是专注于移动注释。

在CSS中,我看到了小部件区域的代码:

.site-content .widget-area {
    margin-top: 27px;
    padding-top: 24px;
    border-top: 3px solid #eee;
}
@media screen and (min-width: 50em) {
    .site-content .widget-area {
        float: right;
        overflow: hidden;
        width: 28%;
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
    }
}

你说:

  

然后注释区域和FB插件都出现了我想要的方式   出现。

您是否有截图显示您希望它们出现?它肯定有助于找到一种解决方法。

答案 1 :(得分:0)

我计算出蓝山页面使用的是page.php模板文件,与index.php文件相反。

然后经过大量的实验后,我通过将page.php模板文件的底部改为下面来实现它的工作

在修改之前,sidebar.php位于主div之外,与注释相关的代码位于主div之内。

这是修改后代码的样子

<?php get_sidebar(); ?>

</div><!-- #primary -->

<?php
                    // If comments are open or we have at least one comment, load up the comment template
                    if ( comments_open() || '0' != get_comments_number() ) :
                        comments_template();
                    endif;
                ?>



<?php get_footer(); ?>

答案 2 :(得分:0)

我修改了您发布的代码。我添加了结束标记并将注释代码移到它上面,这就是你需要将它放在主div的相同宽度的地方。

此外,get_sidebar呈现一个辅助div,它需要与主div并排放置,以使其在其旁边浮动。我使用firebug来修改代码并附上截图以澄清这就是你要找的东西。

<?php

if ( comments_open() || '0' != get_comments_number() ) :
 comments_template();
 endif;
?>

  </main>

</div><!-- #primary -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

enter image description here