wordpress 获取当前分类id wordpress 获取分类id
发布日期:2020-09-16摘要:wordpress 如何判断分类下有没有子类8;category_parent); 1是functions;category_parent) php这个文件)functionget_catego...
wordpress 如何判断分类下有没有子类
8;category_parent);/.1是functions;category_parent)//.php这个文件)functionget_category_root_id($cat){$this_category=get_category($cat);//取得当前分类while($this_category->若当前分类有上级分类时,循环{$this_category=get_category($this_category->/将当前分类设为上级分类(往上爬)}return$this_category->term_id;/wordpress获取当前分类下的子分类1.将此函数放在你模版的函数中(wordpress3
如何查看WordPress分类目录,标签和文章的ID
一、使用 WordPress 内置函数 get_posts() $posts = get_posts( "numberposts=-1&category=3" );echo count($posts);?>二、使用 WordPress 内置函数 get_category_by_slug()// 将以下"category-name"改成你的分类别名即可echo get_category_by_slug("category-name")->count;?>三、使用 WordPress 内置函数 get_category()// 将以下 cat_ID 改成你的分类 ID 即可echo get_category(cat_ID)->count;?>四、使用 WordPress 的内置函数 wp_list_categories()参数 include 的等号后面 3 改成你想要统计文章数的分类 ID 即可。
最终输出形式为:分类名称(文章数) ,如图像印记(20)五、使用 wpdb 直接查询数据库将以下 PHP 代码放置在主题目录下的 functions.php 中function wt_get_category_count($input = "") {global $wpdb;if($input == "") {$category = get_the_category();return $category[0]->category_count;}elseif(is_numeric($input)) {$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";return $wpdb->get_var($SQL);}else {$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug="$input"";return $wpdb->get_var($SQL);}}然后在需要的地方调用该函数即可,该函数提供三种调用方式:1、在主循环中调出该函数,且不提供参数,则返回第一个分类的文章数:2、提供的参数为数字,且该数字为分类的 ID 号,则返回对应 ID 的分类的文章数:3、提供分类的别名,则返回对应缩略名(别名)的分类文章数:该函数对于含有子分类的分类,文章数统计上会有稍许误差。
对于分类文章数为 0 的情况统计得也不是很好。
如何获取WordPress当前用户信息
先判断下是否登录,然后获取当前用户对象,然后获取当前用户对象的信息,需要哪些用哪些: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参数与标题
?php$category_id = get_cat_id("Category Name");query_posts("the_content(),类型为整数示例用法:<endwhile; endif;if (have_posts()) : while (have_posts()) :出错时返回0,成功则返回分类ID号:<?>.$category_id);cat=";?php get_cat_ID( $cat_name ) ;参数:$cat_name 分类名称 默认值为"General": the_post();。
类型为字符型可选返回的值...
如何获取WordPress当前用户信息
这样:$term_ids = array(1,2,3,4,5,6);foreach($term_ids as $term_id){$term_id = sanitize_term_field($term_id);$term = get_term_by("id",$term_id);//输出名称echo $term->name;echo "";//输出链接echo get_term_link( intval($term_id), "category");//category或者其它你自定义的taxonomy}祝愉快!
帝国cms怎么获取当前自定义页面所在分类的ID
查看WordPress分类目录的ID进入仪表盘,打开“分类目录”管理界面,然后把鼠标移动到某一个分类目录名称上,这时就会在网页左下角显示当前分类目录的编辑页面地址。
如图:我们可以看到在显示的网址中有“ID=***”的字符,那么其中显示的数字即为该分类目录的ID。
查看WordPress标签的ID按照同上的方法,进入标签管理界面,我们把鼠标移动到某个标签上面,即可在页面左下角看到该标签的管理页面网址 ,这其中的“ID=”后所跟的数字即为该标签的ID。
查看WordPress文章的ID同样的方法,在文章管理界面中,我们把鼠标移动到某篇文章的名称上,就会在页面左下角看到该篇文章的编辑页面网址 。
这其中的“ID=”后所跟的数字即为该文章的ID。
如何让wordpress的文章只显示在子分类而不显示在父分类
WordPress先判断下是否登录,然后获取当前用户对象,然后获取当前用户对象的信息,需要哪些用哪些:1234567891011121314if(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 . "";}
-
给我们打电话
7*24小时服务热线:1399999999
全国客服热线:400-0000-000 -
百度地图
福建省漳州市 -
给我们发邮件
E-mail:[email protected]
在线沟通