当我查询类别(category.php)时,如何获取当前类别的标题,即正在查询的类别的标题?
我如何获得标签和日期的标题(是日期、月份还是年份)?
当我查询类别(category.php)时,如何获取当前类别的标题,即正在查询的类别的标题?
我如何获得标签和日期的标题(是日期、月份还是年份)?
用于类别使用single_cat_title
功能:
http://codex.wordpress.org/Function_Reference/single_cat_title
用于标记使用single_tag_title
功能:
http://codex.wordpress.org/Function_Reference/single_tag_title
用于日期使用get_the_date
功能:
http://codex.wordpress.org/Function_Reference/get_the_date
例如,如果打开twentyten主题,您将看到以下内容:
类别php:
<h1 class="page-title"><?php
printf( __( \'Category Archives: %s\', \'twentyten\' ), \'<span>\' . single_cat_title( \'\', false ) . \'</span>\' );
?></h1>
日期。php:<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( \'Daily Archives: <span>%s</span>\', \'twentyten\' ), get_the_date() ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( \'Monthly Archives: <span>%s</span>\', \'twentyten\' ), get_the_date( _x( \'F Y\', \'monthly archives date format\', \'twentyten\' ) ) ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( \'Yearly Archives: <span>%s</span>\', \'twentyten\' ), get_the_date( _x( \'Y\', \'yearly archives date format\', \'twentyten\' ) ) ); ?>
<?php else : ?>
<?php _e( \'Blog Archives\', \'twentyten\' ); ?>
<?php endif; ?>
</h1>
除其他答案外,您还可以致电:single_term_title(\'Currently browsing: \')
显示“当前浏览术语”(其中术语是您正在查看的分类术语的名称)(See Codex)
这适用于自定义分类法以及类别和标记术语。
此外,您可能会发现它更易于使用wp_title
它处理分类和归档,根据您正在查看的内容显示适当的标题。它本质上是在显示标题的所有可用功能之间切换,因此您可能需要查看source code. 其他包括:
single_post_title()
对于帖子get_the_date()
对于基于日期的存档get_the_author() 对于基于作者的档案尝试以下操作
<?php single_cat_title(); ?>
<?php single_tag_title(); ?>
<?php the_time(\'F jS, Y\'); ?> // day, month, year
<?php the_time(\'F, Y\'); ?> // month, year
<?php the_time(\'Y\'); ?> // year
有关日期格式的更多信息,请参见法典:HEREPS。这些将在循环中调用。Except the first two 必须在循环之外。
感谢您的回复!我为日期做了这个:
对于archive.php
<?php
/*get archives header*/
if ( is_day() ) { $this_header = "Daily archives for " . get_the_date(); }
else if ( is_month() ){ $this_header = "Monthly archives for " . get_the_date(\'F, Y\'); }
else if ( is_year() ){ $this_header = "Yearly archives for " . get_the_date(\'Y\'); }
else { $this_header = "Archives"; }
?>
那就<?php echo $this_header; >
这可能比你现在需要的更多,但可能是你在主题的其他方面需要的东西。
此代码获取当前帖子的类别名称,然后通过类别将其显示为指向类别中列出的帖子的链接。php文件。
<?php
$category = get_the_category();
$current_category = $category[0];
$parent_category = $current_category->category_parent;
if ( $parent_category != 0 ) {
echo \'<a href="\' . get_category_link($parent_category) . \'">\' . get_cat_name($parent_category) . \'</a>\';
}
echo \'<a href="\' . get_category_link($current_category) . \'">\' . $current_category->cat_name . \'</a>\';
?>
我有一个小部件,我需要添加一个类别选择列表。最终用户应该能够选择一个类别,我需要用小部件保存类别ID。我遇到了一个绊脚石,因为我无法使排除数组正常工作。被排除在外的猫仍会出现在下拉列表中。我做错了什么?function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( \'title\' => \'\', \'text\' => \'\', \'hide_title\' =>