列出类别作者的Wordpress
如何列出类别的作者 例如:列出类别作者的Wordpress,wordpress,wordpress-theming,Wordpress,Wordpress Theming,如何列出类别的作者 例如: CAT NAME: INTERNET AUTHOR: JOHN, DOE, ALEX CAT NAME: TECH AUTHOR: JOHN CAT NAME: CODE AUTHOR: ALEX 您知道如何在Wordpress中执行此操作吗?您可以使用以下代码: <?php $cat_arr = get_categories(); // Get the list of Categories foreach ($cat_
CAT NAME: INTERNET AUTHOR: JOHN, DOE, ALEX
CAT NAME: TECH AUTHOR: JOHN
CAT NAME: CODE AUTHOR: ALEX
您知道如何在Wordpress中执行此操作吗?您可以使用以下代码:
<?php
$cat_arr = get_categories(); // Get the list of Categories
foreach ($cat_arr as $cat_obj) {
$term_id = $cat_obj->term_id;
// Print the Name
?>
<br>
CAT NAME: <?php echo $cat_obj->name ?>, AUTHOR:
<?php
// Get all Posts of that Category
$posts = get_posts(array('category'=>$term_id));
$authors_arr = array();
foreach ($posts as $post_obj) {
$author_id = $post_obj->post_author;
// In depends on where you put this code, the include of the file is required
if (!function_exists('get_userdata')) {
include '<your WP folder>/wp-includes/pluggable.php';
}
$user_obj = get_userdata($author_id);
// Only Add the author is isn't already added, to avoid printed twice
if (!in_array($user_obj->user_login, $authors_arr)) {
$authors_arr[] = $user_obj->user_login; // Instead of user_login you can use any Database field of the "Users" table
}
}
echo implode(', ', $authors_arr) . '<br>';
}
?>
$cat_obj = get_the_category(); // This is what you put in your comment to get Current Category
$term_id = $cat_obj->term_id;
// Print the Name
?>
<br>
CAT NAME: <?php echo $cat_obj->name ?>, AUTHOR:
<?php
// Get all Posts of that Category
$posts = get_posts(array('category'=>$term_id));
$authors_arr = array();
foreach ($posts as $post_obj) {
$author_id = $post_obj->post_author;
// In depends on where you put this code, the include of the file is required
if (!function_exists('get_userdata')) {
include '<your WP folder>/wp-includes/pluggable.php';
}
$user_obj = get_userdata($author_id);
// Only Add the author is isn't already added, to avoid printed twice
if (!in_array($user_obj->user_login, $authors_arr)) {
$authors_arr[] = $user_obj->user_login; // Instead of user_login you can use any Database field of the "Users" table
}
}
echo implode(', ', $authors_arr) . '<br>';
猫名:,作者:
伟大的作品!非常感谢@gsc Leticia你能看看这张照片吗?我怎么做?我知道我不知道很好的Php编码。最后,你的代码工作得很好,我只需要链接作者姓名。我怎么做?我尝试使用wordpress函数,但它与您的代码不兼容。您能再次帮助我吗?:)@gsc leticia RegardsHello,您可以通过以下内容获取作者链接:get_admin_url()user edit.php?user_id='$作者id;关于看图片我不知道你需要什么