最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - Css and function issue on author archive page

programmeradmin2浏览0评论

my posts doesnt seem good.Also I want to display comment counts and tags of post.How can I do it?

/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="" 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:

also category page layout crashes:

/category/uncategorized/

loop.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="" 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; ?>

my posts doesnt seem good.Also I want to display comment counts and tags of post.How can I do it?

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/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:

also category page layout crashes:

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

loop.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/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; ?>
Share Improve this question edited Feb 8, 2020 at 11:34 ahmet kaya asked Feb 8, 2020 at 9:18 ahmet kayaahmet kaya 52 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

1) The messed up layout

It looks like you're missing one closing </div> in your markup. Adding it on a line between <?php endif; ?> and <?php get_sidebar(); ?> should do the trick.

As a side note, you have h3 nested inside a h4 which is invalid markup.

2) Adding styling to your site

In WordPress the proper way of adding styles is to use the theme's stylesheet instead of hard coding the style tags to your templates. So just remove the style tag from your template and move the css to your (child) theme's styles.css file.

Do the same thing for the style tag that can be seen before the doctype declaration in your page source code.

You can read more about adding styles to your site here, https://developer.wordpress/themes/basics/including-css-javascript/#stylesheets

3) Comment count

In your loop you can use comments_number to "Display the language string for the number of comments the current post has." Refer to the code reference to see the parameters you can pass to the function. For example,

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

4) Post tags

In your loop you can use the_tags() template function to display the post tags. This function too takes some parameters, which are described in the code reference.

<p><?php the_tags(); ?></p>

Or if you want to have more control on the tag output html, then you can use get_the_tags() instead in your loop. Simplified example,

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

评论列表(0)

  1. 暂无评论