WordPress企业主题定制/开发/优化

wordpress 常见问题集合, 不断更新

首页 » WORDPRESS主题技术 » wordpress 常见问题集合, 不断更新


一. get_the_ID()与$post->ID如何使用?

get_the_ID()与$post->ID都可以获取当前文章的ID,但是前者一般用在循环内,如:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php while (have_posts()) : the_post(); ?>
<tr>
<td height="25"><?php $xx1=get_the_ID();?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php if($xx1==$xx) { ?><strong><?php the_title(); ?></strong><?php } else{?><?php the_title(); ?><?php }?></a></td>
<?php if($idbok==3) {  ?><td><?php the_time('d.m.Y') ?></td><?php } ?>
</tr>
<?php endwhile; ?>
</table>

$post->ID的用法一般是:
<?php if($post->ID==4) {?>
<a href="#"  target="_blank">符合条件的内容</a>
<?php }?>


二. get_the_category()的用法

get_the_category()用于获取当前文章的分类:如:
<?php
//获取文章所属分类中的第一个分类
$category = get_the_category();
$idbok=$category[0]->cat_ID;
?>

cat_ID:当前类别的ID(也可以写作’term_id’);
cat_name:当前类别的名称(也被写作’name’);
category_description:当前分类的描述(也可以写作’description’);
category_count:属于当前分类的文章数量(也被写作’count’)。

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签