Monday 29 August 2016

How to Display a list of the Authors in WordPress

In the last article, I described how to conclude the recording of the author, in this I want to make a similar conclusion, but not quite. Sometimes you have to bring all the authors of the site, not just the users, namely those who have published their articles on your site. If you want to develop a website on wordpress read it.

In this article I'll show you how to get a block with information about the authors. You will be able to see which features are used and need to turn off unnecessary.


Blog Authors

authors

I recently made ​​a website where the customer requested on the main page to list the site authors. His plan was to make an informative site for the company, where the staff could publish their articles. To carry out such a conclusion, it was used by the function, which brings together a number of WordPress functions. Below is ready to function code that you want to add custom functions to a file the functions.php .

/*The list of authors*/
function contributors() {
global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
foreach($authors as $author) {?>
<li><div class="authorava"><?php echo get_avatar($author->ID);?><br><div class="author_name"><?php the_author_meta('display_name', $author->ID);?></div></div>
<div class="textauthor">
<span>:<br></span> <?php the_author_meta('description', $author->ID);?><br>
<a href="<?php get_bloginfo('url')?>/?author=<?php echo $author->ID;?>">authors</a>
</div>
</li>
<?php }
}

First, we create a function contributors , which will access the database and take the ID of the authors, due to which, it will be possible to use other functions to display the desired information.

The author will be displayed in the UL , this inside add tag li .

Then add in the blocks with the withdrawal of certain elements. The first block with a class - author_name. In its conclusions the avatar with the function of the echo get_avatar ($ author-> ID); . Then it has a unit with class author_name , in which the function name with the conclusion - the_author_meta ( 'display_name', $ author-> ID); .

After the unit is text author , which displays information about the author using the - the_author_meta ( 'description', $ author-> ID); . To hatched information, the author must fill out the information about MYSELF in the profile settings.

At the end of a link to a list of all posts of the author.

In order to list, must now connect function in WordPress theme. In my case it was the index.php , you can have a completely different file. In general, in the right place add the following line:


<ul id="authorlist"><?php contributors(); ?></ul>
Now add styles to file the style.css , to arrange everything nicely.

ul#authorlist{font-size:12px;color:#555;list-style:none;margin:0;}
.textauthor{margin-left:10px;overflow:hidden;}
.textauthor span{font-weight:bold;}
.authorava{float:left;width:110px;text-align:center;}
.authorname{width:100px;font-weight:bold;color:#458ea1;}
.authname{margin: 20px 0 0 10px;float: left;}

Styles may change by itself, and the function itself can also be cut by removing unnecessary features.

In addition, all done without plug-ins, there is a definite plus. Read about 403 Error on Wordpress Login Page 

No comments:

Post a Comment