wordpress 通过the_title()和get_the_title函数获取文章标题
the_title() 输出或返回当前文章标题。此标签用在主循环里。如果此文章是受密码保护的或者是私有的,
就会在文章标题前标记上"Protected:"或者"Private:"字样。
用法: <?php the_title( $before, $after, $echo ); ?>
参数:
$before 字符串型,标题之前放置的文本,默认是空
$after 字符串型,标题之后放置的文件,默认是空
$echo 逻辑型,true表示显示标题,false表示返回它并用在PHP中,默认为true.
示例:
<?php the_title('<h3>', '</h3>'); ?>
get_the_title() 通过文章ID返回文章标题。如果此文章是受密码保护的或者是私有的就会在文章标题前标记上"Protected:"或者"Private:"字样。
用法:<?php echo get_the_title(ID); ?>
示例:
eg1:
<?php
query_posts('cat=1');
$dropdown="<select name='dropdown'>";
while (have_posts()):the_post();
$dropdown.="<option value='".get_the_title()."'>".get_the_title()."</option>";
endwhile;wp_reset_query();
$dropdown.="</select>";
echo $dropdown;
?>
eg2:
<div class='breadcrumb'>
<?php
$parent_title = get_the_title($post->post_category);
if($parent_title != the_title("<h3>","<h3>",false)) {
echo ('<a href="'.get_permalink($post->post_category).'" title="'.$parent_title . '">'.$parent_title.'</a> »');
}
?>
<a href='<?php the_permalink() ?>' rel='bookmark' title='<?php the_title(); ?>'>
<?php the_title(); ?></a> »
</div>
Values
$post->post_status
$post->comment_status
$post->ping_status
$post->post_pingback
$post->post_category
$post->post_content
$post->post_title
$post->post_excerpt
$post->page_template
$post->post_parent
$post->menu_order
源文件:the_title()和get_the_title()都在wp-includes/post-templete.php文件。
|