1.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 . ''; //当前文章的分类的名称
}
2.wordpress取得子分类id
$categories_shop = get_categories("echo=0&show_count=1&child_of=".$hot_shop_id."&title_li=&orderby=count&order=DESC&hide_empty=0&number=14");
foreach($categories_shop as $category) {
//ID $category->cat_ID
//名称 $category->cat_name
}
3.如何取消wordpress各个页面的阅读次数
点击wordpress后台的外观--编辑按钮。
选择你的模板,然后找到loop.php这个文件。
打开,找到以下这段代码:
<span><i class="icon-eye-open icon-large"></i>; 围观<?php echo getPostViews(get_the_ID()); ?>;次</span>。
将这段文字删除,然后点击下面的更新文件就可以了。这样,首页和分类目录下文章标题下的“阅读次数”就没啦!
接下来,我们来去掉文章页面的阅读次数。找到loop-single.php这个文件,打开,找到以下代码
<span><i class="icon-eye-open icon-large"></i>; 围观<i id="number"><?php echo getPostViews(get_the_ID());if($_SERVER["QUERY_STRING"])setPostViews(get_the_ID())?></i><script type="text/javascript">jQuery(function($){$.get("<?php bloginfo('url')?>/fo_ajax?ajax=getPostViews&postID=<?php echo get_the_ID()?>",function(data){if(data.length < 10)$('#number').text(data)});})</script>;次</span>。
将其删除。点击下面的“更新文件”按钮保存。这样,文章页面的“阅读次数”也消失了!
4.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 '
5.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!'; }?> 说的全在注释里了。
6.wordpress如何根据分类ID获取分类标题
用法:
参数:$cat_name 分类名称 默认值为"General"。类型为字符型可选
返回的值:出错时返回0,成功则返回分类ID号,类型为整数
示例:
query_posts('cat='.$category_id);
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;
?>
7.wordpress如何根据分类ID获取分类标题
用法:<?php get_cat_id(="" $cat_name="" )="" ?="">参数:$cat_name 分类名称 默认值为"General"。
类型为字符型可选返回的值:出错时返回0,成功则返回分类ID号,类型为整数示例:<?php $category_id="get_cat_id('Category" name');="" query_posts('cat='.$category_id); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; ?>。
转载请注明出处51数据库 » wordpressgettheid
布鲁布鲁鲁