您的位置:首页 > 其它

wordpress 通过the_title()和get_the_title函数获取文章标题

2014-08-25 09:31 330 查看
the_title() 输出或返回当前文章标题。此标签用在主循环里。如果此文章是受密码保护的或者是私有的,

就会在文章标题前标记上"Protected:"或者"Private:"字样。

用法: <?phpthe_title( $before, $after, $echo ); ?>

参数:

$before 字符串型,标题之前放置的文本,默认是空

$after 字符串型,标题之后放置的文件,默认是空

$echo 逻辑型,true表示显示标题,false表示返回它并用在PHP中,默认为true.

示例:

<?phpthe_title('<h3>','</h3>'); ?>

get_the_title()通过文章ID返回文章标题。如果此文章是受密码保护的或者是私有的就会在文章标题前标记上"Protected:"或者"Private:"字样。

用法:<?phpecho get_the_title(ID); ?>

示例:

eg1:

<?php

query_posts('cat=1');

$dropdown="<selectname='dropdown'>";

while(have_posts()):the_post();

$dropdown.="<optionvalue='".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 ('<ahref="'.get_permalink($post->post_category).'"title="'.$parent_title .'">'.$parent_title.'</a>»');

}

?>

<a href='<?php the_permalink()?>' rel='bookmark' title='<?phpthe_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文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: