wordpress如何获得当前自定义分类的id
当前页是分类页
系统默认有个变量$cat,就是当前分类的ID
当前页是单页
第一种方法
$cat= single_cat_title('', false);
echo get_cat_ID($cat); 第二种方法
if (!is_page() && !is_home()){
$catsy = get_the_category(); $myCat = $catsy[0]->cat_ID; $currentcategory = '¤t_category='.$myCat;
}
wp_list_categories('hierarchical=1&use_desc_for_title=0&exclude=12&depth=1&orderby=id&title_li='.$currentcategory); 第三种方法
foreach((get_the_category()) as $category) {
echo $category->cat_ID . ''; //当前文章的分类的ID
echo $category->cat_name . ''; //当前文章的分类的名称
}
wordpress如何获取当前文章的id,要求写一个函数在function里面调用-
<?php the="" args="" $args="array(" 'cat'=""> 61 //这是分类ID,也可以用array给一组ID ); // The Result $naruco= new WP_Query( $args ); if ( $naruco-> have_posts() ) { // The Loop while ( $naruco-> have_posts() ) : $naruco->the_post(); echo ''; $post_ID = get_the_ID(); //这就是文章的ID了。
$post_content = get_the_content(); //文章内容,至于怎么截取一定长度的字数,百度一下到处都是啦。 echo ''; endwhile; }else { echo 'no posts in current category!'; }?> 说的全在注释里了。
wordpress中怎么获取会员登录后的ID号
分类目录的id号的查询: 到网站的后台找到文章分类目录,用鼠标放到所创建的分类目录上看电脑的左下角处的显示,如图中所示id=5就是分类目录的id号了。
页面的id号查询:也是同样的道理,在网站的后台,找到页面中你所创建的所有的页面,选择其中的一个页面,用鼠标放到所想查看的一个页面上,在左下角同样也可以看到页面的id号了,如图中所示post=84即为页面的id号了。 文章标题的id号的查询:到网站的后台点击文章所有文章选择其中一篇的文章,用鼠标放到文章的标题上面,在左下角看到如图中所示,post=558即为文章标题的id号了。
。
为WordPress文章自动添加自定义栏目
自定义栏目是WordPress 一个非常强大的功能,借助它我们可以实现很多特殊的功能.本文的一段代码可以为文章自动添加预先设置好的自定义栏目名称及值,而无需手动添加. WordPress自定义栏目 将下面的代码添加到当前主题的 functions.php 文件: add_action('publish_page', 'add_custom_field_automatically'); add_action('publish_post', 'add_custom_field_automatically'); function add_custom_field_automatically($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, 'field-name', 'custom value', true); } } 你只需替换其中的自定义栏目名称:field-name,值:custom value 之后,当你发布文章后,相应的自定义栏目名称及值会自动添加到文章中.。
wordpress如何获取当前文章的id,要求写一个函数在function里面调用
$args = array(
'cat' =>61 //这是分类ID,也可以用array给一组ID
);
// The Result
$naruco= new WP_Query( $args );
if ( $naruco-> have_posts() ) {
// The Loop
while ( $naruco-> have_posts() ) : $naruco->the_post();
echo '
wordpress模板,请教如何通过栏目(或单页)的别名得到栏目(或单
wp里有通过单页ID和栏目ID来获取永久链接的方法,函数分别是get_permalink和get_category_link。
知道了slug后,通过查询数据库得到该slug的ID,写一个函数:function geturl($slug, $type="page") { //slug global $wpdb; if ($type == "page") { $url_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$slug."'"); echo get_permalink($url_id); }else { $url_id = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE slug = '".$slug."'"); echo get_category_link($url_id); }}调用方法:<?php geturl("slugname","page");="" 单页="" ?=""><?php geturl("slugname","cat");="" 类别="" ?="">。
转载请注明出处51数据库 » wordpress当前栏目id
?php>?php>?php>
段友812243