调用wordpress数据库ID(wordpress数据库连接)
大家好!今天让创意岭的小编来大家介绍下关于调用wordpress数据库ID的问题,以下是小编对此问题的归纳整理,让我们一起来看看吧。
开始之前先推荐一个非常厉害的Ai人工智能工具,一键生成原创文章、方案、文案、工作计划、工作报告、论文、代码、作文、做题和对话答疑等等
只需要输入关键词,就能返回你想要的内容,越精准,写出的就越详细,有微信小程序端、在线网页版、PC客户端
创意岭作为行业内优秀的企业,服务客户遍布全球各地,如需了解SEO相关业务请拨打电话175-8598-2043,或添加微信:1454722008
本文目录:
一、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)下最新评论的5篇文章
wordpress 采用的是 无线分类方式
类似于:
id name fuid
1 书 o
2 数学书 1
3 代数 2
4 语文书 1
5 文言文 4
然后你的 你的sql语句 就是
select * from 表 where fuid=1 就是所有的书。
select * from 表 where fuid=2 就是说有的数学书
三、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;
?>
四、wordpress在不破坏css的情况下,指定id调用最新文章(文章显示数量也要设置)
显示循环部分代码
<?php if(have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<div class="col col_2">
<img src="<?php if ( get_post_meta($post->ID, 'thumbnail', true) ) {echo get_post_meta($post->ID, 'thumbnail', true);}elseif ( has_post_thumbnail() ){$thumbnail_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail'); echo $thumbnail_image_url[0]; }else{ echo catch_first_image(); }?>" alt="<?php the_title(); ?>" class="image_frame" />
</div>
<div class="col col_2 no_margin_righ">
<h4><?php the_title(); ?></h4>
<p><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); ?></p>
<a href="<?php the_permalink(); ?>" class="more">More</a>
</div>
<div class="cleaner"></div>
</div>
<?php endwhile; endif; ?>
主题functions.php添加特色图代码和获取文章第一张图的代码
/*自定义缩略图*/
if(function_exists('add_image_size')){
add_image_size('featured',300,200,true); //尺寸自己修改
add_image_size('thumbnail',195,195,true); //尺寸自己修改,这是后面用到的
}
/*抓取第一张缩略图*/
functioncatch_first_image(){
global$post,$posts;
$first_img='';
ob_start();
ob_end_clean();
$output=preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',$post->post_content,$matches);
$first_img = $matches[1][0];
if(empty($first_img)){//自定义第一张图片
$random = mt_rand(1,6);
$first_img = get_bloginfo('stylesheet_directory')."/images/random/".$random.".jpg"; //如文章无图片,则随机显示6张图片中一张,文件夹目录注意下images/random
}
return $first_img;
}
以上只是参考。
以上就是关于调用wordpress数据库ID相关问题的回答。希望能帮到你,如有更多相关问题,您也可以联系我们的客服进行咨询,客服也会为您讲解更多精彩的知识和内容。
推荐阅读:
调用wordpress数据库ID(wordpress数据库连接)