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

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>&raquo;');
 
  }
     
?>

<a href='<?php the_permalink()?>' rel='bookmark' title='<?phpthe_title(); ?>'>

<?php the_title();?></a>&raquo;

</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文件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值