wordpress 如何根据文章ID输出正确内容,有代码!
先判断下是否登录,然后获取当前用户对象,然后获取当前用户对象的信息,需要哪些用哪些:if(is_user_logged_in()){$current_user = wp_get_current_user();/*** @example Safe usage: $current_user = wp_get_current_user();* if ( !($current_user instanceof WP_User) )* return;*/echo 'Username: ' . $current_user->user_login . '';echo 'User email: ' . $current_user->user_email . '';echo 'User first name: ' . $current_user->user_firstname . '';echo 'User last name: ' . $current_user->user_lastname . '';echo 'User display name: ' . $current_user->display_name . '';echo 'User ID: ' . $current_user->ID . '';}
怎么让wordpress文章ID连续
$post_num = 10; // 设置调用条数$args = array('post_password' =>”,'post_status' =>'publish', // 只选公开的文章.'post__not_in' =>array($post->ID),//排除当前文章'caller_get_posts' =>1, // 排除置顶文章.'orderby' =>'comment_count', // 依评论数排序.'posts_per_page' =>$post_num);$query_posts = new WP_Query();$query_posts->query($args);while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>以上是热门文章的调用代码,放在侧边栏试试就知道了
wordpress文章结尾处显示文章作者和作者信息
你好!以下是wordpress常用的信息调用方法,参考下:显示文章的作者显示文章作者的描述(作者个人资料中的描述)显示文章作者的登录名显示文章作者的firstname(名)显示文章作者的lastname(姓)显示文章作者的昵称显示文章作者的ID号显示文章作者的电子邮箱显示文章作者的网站地址(添加于2.1版本) 显示一个以文章作者名为链接名,链接地址为文章作者的网址的链接。
(不推荐使用) 显示文章作者的icq显示文章作者的aim显示文章作者的yim(不推荐使用) 显示文章作者的msn显示文章作者已发表文章的篇数显示一个链接到文章作者已发表文章列表的链接(不推荐使用) 显示blog所有作者和他们的相关信息。
完整函数如下:参数:optioncount:是否显示各作者已发表文章的篇数,可选值为:TRUE 和 FALSE(默认值)exclude_admin:是否不列出管理员,可选值为:TRUE(默认值) 和 FALSEshow_fullname :是否显示各作者的全名,可选值为:TRUE 和 FALSE(默认值)hide_empty:是否不显示发表文章数为0的作者,可选值为:TRUE(默认值) 和 FALSEfeed:链接到各个作者发表文章的RSS供稿种子链接名,默认为空,不显示RSS供稿种子feed_image:供稿种子的图片地址,如果提供此项,则覆盖上面的feed,默认为空显示blog作者列表,如果作者发表过文章,则他的名字将链接到他发表的文章列表中。
可定义是否显示其他信息。
参数:optioncount:是否显示各个作者发表文章数,可选值:true 和 false(默认值)exclude_admin:是否不显示”admin”用户,可选值:true(默认值) 和 falseshow_fullname:是否显示各个作者的全名,如果不显示,将显示昵称。
可选值:true 和 false(默认值)hide_empty:是否不显示发表文章数为0的作者,可选值:true(默认值) 和 falsefeed:链接到各个作者发表文章的RSS供稿种子链接名,默认为空,不显示RSS供稿种子feed_image:供稿种子的图片地址,如果提供此项,则覆盖上面的feed,默认为空。
希望我的回答能够帮到你,采纳哈~
wordpress程序,怎样可以获取当前文章分类下的所有文章,并且打印...
可分2步走:1、先获取指定文章(ID)的所有分类ID2、根据分类ID,重新query据此思路,提供代码如下:if ( ! function_exists('wpdit_get_posts_in_same_categories') ) {function wpdit_get_posts_in_same_categories( $post_id ){$post = get_post( $post_id );if ( ! $post )return;$categories = get_the_category($post_id);if ( ! count( $categories ) )return;$cid = array();foreach ( $categories as $key =>$category ) {$cid[] = $category->term_id;}$args = array('post__not_in' =>array( $post_id ),'category__in' =>$cid,);$relate_posts = get_posts( $args );if ( is_wp_error($relate_posts) )return;foreach ($relate_posts as $key =>$relate_post ) {printf( '',get_permalink( $relate_post->ID ),get_the_title( $relate_post->ID ));}}}将wpdit_get_posts_in_same_categories( the_ID() );放于需要的地方,只要指定post_id即可。
(要在文章获取的循环内,否则the_ID()无结果)
wordpress 如何通过ID来调用tag标签
试试获得指定分类目录id或指定TAG标签id,之后就可以在需要的地方使用如下代码来调用functions文件里的函数就可以实现想要的功能了:if (is_category()) { get_most_viewed_category(get_current_category_id()); } elseif (is_tag()) { get_most_viewed_tag(get_current_tag_id()); } else { get_most_viewed(); } ?>
如何用 WordPress 写出一篇“好看”的文章
方法一:标签相关首先获取文章的所有标签,接着获取这些标签下的 n 篇文章,那么这 n 篇文章就是与该文章相关的文章了。
现在可以见到的WordPress相关文章插件都是使用的这个方法。
下面是实现的代码:global $post;$post_tags = wp_get_post_tags($post->ID);if ($post_tags) {foreach ($post_tags as $tag) {// 获取标签列表$tag_list[] .= $tag->term_id;}// 随机获取标签列表中的一个标签$post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];// 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表$args = array('tag__in' =>array($post_tag),'category__not_in' =>array(NULL), // 不包括的分类ID'post__not_in' =>array($post->ID),'showposts' =>6, // 显示相关文章数量'caller_get_posts' =>1);query_posts($args);if (have_posts()) {while (have_posts()) {the_post(); update_post_caches($posts); ?>* }}else {echo '* 暂无相关文章';}wp_reset_query();}else {echo '* 暂无相关文章';}?>方法二:分类相关本方法是通过获取该文章的分类id,然后获取该分类下的文章,来达到获取相关文章的目的。
global $post;$cats = wp_get_post_categories($post->ID);if ($cats) {$args = array('category__in' =>array( $cats[0] ),'post__not_in' =>array( $post->ID ),'showposts' =>6,'caller_get_posts' =>1);query_posts($args);if (have_posts()) {while (have_posts()) {the_post(); update_post_caches($posts); ?>* }} else {echo '* 暂无相关文章';}wp_reset_query(); }else {echo '* 暂无相关文章';}?>
转载请注明出处51数据库 » wordpress 文章 id