在 WordPress 裡我們可以透過 the_title() 來取得文章標題。

使用方法是當我們用 the_post() 取得文章內容後,就可以使用 the_title() 來取得文章標題。

用法如下:

the_title( string $before = '', string $after = '', bool $echo = true )

可以丟進去的參數有文章標題前面的 html 內容、後面的 html 內容,以及是否要 echo。

範例:

the_title( '<h1 class="page-title">', '</h1>');

 

參考:

the_title()