📜  wordpress 获取存档标题 - PHP (1)

📅  最后修改于: 2023-12-03 14:48:33.126000             🧑  作者: Mango

Wordpress 获取存档标题 - PHP

如果你想在页面上展示 Wordpress 博客的存档标题(archive titles), 你可以使用下面的代码:

<?php
if (is_category()) {
  $title = single_cat_title('', false);
} elseif (is_tag()) {
  $title = single_tag_title('', false);
} elseif (is_author()) {
  $title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif (is_day()) {
  $title = get_the_date();
} elseif (is_month()) {
  $title = get_the_date('F Y');
} elseif (is_year()) {
  $title = get_the_date('Y');
} elseif (is_tax()) {
  $title = single_term_title('', false);
} else {
  $title = 'Archives';
}
echo $title;
?>

上面的代码可以根据当前页面的类型(category, tag, author, day, month, year, custom taxonomy)显示相应的存档标题。

返回的 markdown 格式如下:

# Wordpress 获取存档标题 - PHP

如果你想在页面上展示 Wordpress 博客的存档标题(archive titles), 你可以使用下面的代码:

```php
<?php
if (is_category()) {
  $title = single_cat_title('', false);
} elseif (is_tag()) {
  $title = single_tag_title('', false);
} elseif (is_author()) {
  $title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif (is_day()) {
  $title = get_the_date();
} elseif (is_month()) {
  $title = get_the_date('F Y');
} elseif (is_year()) {
  $title = get_the_date('Y');
} elseif (is_tax()) {
  $title = single_term_title('', false);
} else {
  $title = 'Archives';
}
echo $title;
?>

上面的代码可以根据当前页面的类型(category, tag, author, day, month, year, custom taxonomy)显示相应的存档标题。