作者档案页面上的css和函数问题

时间:2020-02-08 作者:ahmet kaya

我的帖子看起来不太好。我还想显示评论计数和帖子标签。我该怎么做?

http://www.migrate2.deniz-tasarim.site/author/admin/

<?php get_header(); ?>







    <style>
        .main-section{
            padding:15px;
            background-color: #fff;
        }
        .list-inline-item{
            border-right:1px solid black;
            padding-right:6px;
            line-height:0.4em;
        }
        .list-inline-item:last-child{
            border:none;
        }
        .post-detail ul{
            margin-top:15px;
        }
    </style>


<?php
// Set the Current Author Variable $curauth
$curauth = (isset($_GET[\'author_name\'])) ? get_user_by(\'slug\', $author_name) : get_userdata(intval($author));
?>

<div class="author-profile-card">
    <h2>About: <?php echo $curauth->nickname; ?></h2>
    <div class="author-photo">
        <?php echo get_avatar( $curauth->user_email , \'90 \'); ?>
    </div>
    <p><strong>Website:</strong> <a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a><br />
        <strong>Bio:</strong> <?php echo $curauth->user_description; ?></p>
</div>

<h2>Posts by <?php echo $curauth->nickname; ?>:</h2>

    <div class="container main-section border">
        <div class="row">
            <div class="col-lg-12 col-sm-12 col-12">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>


                <div class="row">
                    <div class="col-lg-2 col-sm-2 col-5">
                        <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                <?php the_post_thumbnail(array(150,150), [\'class\' => \'img-thumbnail\']); // Declare pixel size you need inside the array ?>
                            </a>
                        <?php endif; ?>
                    </div>
                    <div class="col-lg-10 col-sm-10 col-7">
                        <h4 class="text-primary">

                            <h3>
                                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
                                    <?php the_title(); ?></a>
                            </h3>

                            Post Title



                        </h4>
                        <p>
                            <?php the_excerpt(); ?>

                        </p>
                        <button class="btn btn-sm btn-dark">Read more</button>
                    </div>
                </div>
                <div class="row post-detail">
                    <div class="col-lg-12 col-sm-12 col-12">
                        <ul class="list-inline">
                            <li class="list-inline-item">
                                <img src="https://dummyimage.com/20x20/a8a1a8/0f0f12" class="rounded-circle" width="20px"> <span>by</span> <span class="text-info">Lisa</span>
                            </li>
                            <li class="list-inline-item">
                                <i class="fa fa-calendar" aria-hidden="true"></i>
                                <span>

                                <p class="posted-on"><?php the_time(\'d M Y\'); ?></p>
                            </span>
                            </li>
                            <li class="list-inline-item">
                                <i class="fa fa-comment" aria-hidden="true"></i> <span class="text-info">3 Comments</span>
                            </li>
                            <li class="list-inline-item">
                                <i class="fa fa-share-square-o" aria-hidden="true"></i> <span class="text-info">39 Shares</span>
                            </li>
                            <li class="list-inline-item">
                                <i class="fa fa-tags" aria-hidden="true"></i>
                                <span>Tags:</span>
                                <span class="badge badge-dark">bootstrap 4.0</span>
                                <span class="badge badge-dark">laravel</span>
                                <span class="badge badge-dark">html</span>
                                <span class="badge badge-dark">css</span>
                            </li>
                        </ul>
                        <?php edit_post_link(); ?>
                    </div>
                </div>
            </div>
        </div>

<?php endwhile;

// Previous/next page navigation.
    the_posts_pagination();


else: ?>
    <p><?php _e(\'No posts by this author.\'); ?></p>

<?php endif; ?>






<?php get_sidebar(); ?>

<?php get_footer(); ?>

edit:

此外,类别页面布局崩溃:

http://www.migrate2.deniz-tasarim.site/category/uncategorized/

环php:

<?php if (have_posts()): while (have_posts()) : the_post(); ?>


<style>
    .main-section{
        padding:15px;
        background-color: #fff;
    }
    .list-inline-item{
        border-right:1px solid black;
        padding-right:6px;
        line-height:0.4em;
    }
    .list-inline-item:last-child{
        border:none;
    }
    .post-detail ul{
        margin-top:15px;
    }
</style>


<h2>Posts by :</h2>

<div class="container main-section border">
    <div class="row">
        <div class="col-lg-12 col-sm-12 col-12">



            <div class="row">
                <div class="col-lg-2 col-sm-2 col-5">
                    <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail(array(150,150), [\'class\' => \'img-thumbnail\']); // Declare pixel size you need inside the array ?>
                        </a>
                    <?php endif; ?>
                </div>
                <div class="col-lg-10 col-sm-10 col-7">
                    <h4 class="text-primary">

                        <h3>
                            <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
                                <?php the_title(); ?></a>
                        </h3>

                        Post Title



                    </h4>
                    <p>
                        <?php the_excerpt(); ?>

                    </p>
                    <button class="btn btn-sm btn-dark">Read more</button>
                </div>
            </div>
            <div class="row post-detail">
                <div class="col-lg-12 col-sm-12 col-12">
                    <ul class="list-inline">
                        <li class="list-inline-item">
                            <img src="https://dummyimage.com/20x20/a8a1a8/0f0f12" class="rounded-circle" width="20px"> <span>by</span> <span class="text-info">Lisa</span>
                        </li>
                        <li class="list-inline-item">
                            <i class="fa fa-calendar" aria-hidden="true"></i>
                            <span>

                                <p class="posted-on"><?php the_time(\'d M Y\'); ?></p>
                            </span>
                        </li>
                        <li class="list-inline-item">
                            <i class="fa fa-comment" aria-hidden="true"></i> <span class="text-info">3 Comments</span>
                        </li>
                        <li class="list-inline-item">
                            <i class="fa fa-share-square-o" aria-hidden="true"></i> <span class="text-info">39 Shares</span>
                        </li>
                        <li class="list-inline-item">
                            <i class="fa fa-tags" aria-hidden="true"></i>
                            <span>Tags:</span>
                            <span class="badge badge-dark">bootstrap 4.0</span>
                            <span class="badge badge-dark">laravel</span>
                            <span class="badge badge-dark">html</span>
                            <span class="badge badge-dark">css</span>
                        </li>
                    </ul>
                    <?php edit_post_link(); ?>
                </div>
            </div>
        </div>
    </div>














    <!-- article -->
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <!-- post thumbnail -->
        <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                <?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
            </a>
        <?php endif; ?>
        <!-- /post thumbnail -->

        <!-- post title -->
        <h2>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </h2>
        <!-- /post title -->

        <!-- post details -->
        <span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
        <span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
        <span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
        <!-- /post details -->

        <?php html5wp_excerpt(\'html5wp_index\'); // Build your custom callback length in functions.php ?>

        <?php edit_post_link(); ?>

    </article>
    <!-- /article -->

<?php endwhile; ?>

<?php else: ?>

    <!-- article -->
    <article>
        <h2><?php _e( \'Sorry, nothing to display.\', \'html5blank\' ); ?></h2>
    </article>
    <!-- /article -->

<?php endif; ?>

1 个回复
最合适的回答,由SO网友:Antti Koskinen 整理而成

1) The messed up layout

看来你错过了一次机会</div> 在标记中。将其添加到<?php endif; ?><?php get_sidebar(); ?> 应该做到这一点。

作为旁注,你有h3 嵌套在h4 这是无效的标记。

2) Adding styling to your site

在WordPress中,添加样式的正确方法是使用主题的样式表,而不是硬编码style 标记到模板。所以只需移除style 标记模板并将css移动到(子)主题的样式中。css文件。

对于style 可以在doctype 页面源代码中的声明。

您可以在此处阅读有关向站点添加样式的更多信息,https://developer.wordpress.org/themes/basics/including-css-javascript/#stylesheets

3) Comment count

在您的loop 您可以使用comments_number 显示当前帖子评论数的语言字符串参考代码参考以查看可以传递给函数的参数。例如

<span class="comments"><?php comments_number(); ?></span>

4) Post tags

在您的循环中,您可以使用the_tags() 模板函数以显示贴子标记。此函数也接受一些参数,这些参数在代码参考中有描述。

<p><?php the_tags(); ?></p>
或者,如果希望对标记输出html有更多的控制,那么可以使用get_the_tags() 而是在你的循环中。简化示例,

$post_tags = get_the_tags(); 
if ( $post_tags ) {
  foreach( $post_tags as $tag ) {
    echo $tag->name . \', \'; 
  }
}

相关推荐

如何在最后时刻将js/css出队?

我正在尝试删除忍者表单插件中包含的字体很棒的样式表(因为我通过CDN手动包含了最新的FA)。我做到了:add_action(\'wp_enqueue_scripts\', function () { wp_dequeue_style(\'nf-font-awesome\'); }, 100); 但是,插件中包含的版本仍会加载。那么,如何在最后一刻将脚本或样式表出列?很明显,我没有“足够晚”,这就是为什么上述方法不起作用。什么是“迟于”wp_enqueue_scripts?