Comment obtenir le titre de la catégorie et de l'archive?
5 réponses
- votes
-
- 2012-04-12
Pour la catégorie,utilisez lafonction
single_cat_title
:
http://codex.wordpress.org/Function_Reference/single_cat_titlePour lesbalises,utilisez lafonction
single_tag_title
:
http://codex.wordpress.org/Function_Reference/single_tag_titlePour la date,utilisez lafonction
get_the_date
:
http://codex.wordpress.org/Function_Reference/get_the_dateParexemple,si vous ouvrez vingt-dixthèmes,vous verrez ce qui suit:
category.php:
<h1 class="page-title"><?php printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
date.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>
For category use
single_cat_title
function:
http://codex.wordpress.org/Function_Reference/single_cat_titleFor tag use
single_tag_title
function:
http://codex.wordpress.org/Function_Reference/single_tag_titleFor date use
get_the_date
function:
http://codex.wordpress.org/Function_Reference/get_the_dateFor example if you open twentyten theme you will see following:
category.php:
<h1 class="page-title"><?php printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
date.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>
-
est-ce que single_tag_title 'obtient' letitre de labalise ou yfait-il écho?does single_tag_title 'get' the tag title or does it echo it?
- 0
- 2014-02-19
- henrywright
-
le deuxièmeparamètre de `single_tag_title`est responsable de l'écho.si vouspassez `true`,alorsil sera affiché.si «false»,il sera renvoyé.the second parameter of `single_tag_title` is responsible for echoing. if you pass `true`, then it will be displayed. if `false` then it will be returned.
- 0
- 2014-02-20
- Eugene Manuilov
-
- 2012-04-12
Enplus des autres réponses,vouspouvez appeler:
single_term_title('Currently browsing: ')
pour afficher 'Terme denavigation actuel' (oùtermeest lenom de leterme detaxonomie que vous consultez. ( Voir Codex )Celafonctionnepour lestaxonomiespersonnalisées ainsi quepour lestermes de catégorieet debalise.
En outre,voustrouverezpeut-êtreplusfacile d'utiliser
wp_title
quigère lestaxonomieset les archives,affichant letitre appropriéen fonction de ce que vous visualisez. Ilbasculeessentiellemententretoutes lesfonctions disponiblespour afficher lestitres,vous voudrezpeut-êtrejeter un coup d'œil à code source . D'autresincluent:-
single_post_title()
pour lesmessages -
get_the_date()
pour les archivesbasées sur la date - get_the_author () pour les archivesbasées sur l'auteur
In addition to the other answers, you can call:
single_term_title('Currently browsing: ')
to display 'Currenty browsing term' (where term is the name of the taxonomy term you are viewing. (See Codex)This works for custom taxonomies as well category and tag terms.
Also, you might find it easier to use
wp_title
which handles taxonomies and archives, displaying the appropriate title depending on what you are viewing. It essentially switches through all the available functions for displaying titles so you might want to take a look at the source code. Others include:single_post_title()
for postsget_the_date()
for date based archives- get_the_author() for author based archives
-
- 2012-04-12
Essayez ce qui suit
<?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
Pouren savoirplus sur leformatage de la date,consultez le Codex: ICI
PS.Ceux-ci doivent être appelés dans laboucle. Sauf les deuxpremiers qui doivent êtreen dehors de laboucle.
Try the following
<?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
See the Codex for more on formatting the date: HERE
PS. These are to be called within the loop. Except the first two which must be outside the loop.
-
- 2012-04-13
Mercipour vos réponses!J'aifait cecipour la date:
pour 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"; } ?>
alorsjuste
<?php echo $this_header; >
Thank you for your replies! I made this for date:
for 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"; } ?>
then just
<?php echo $this_header; >
-
- 2012-04-13
C'estprobablementplus que ce dont vous avezbesoinpour lemoment,mais c'estprobablement quelque chose dont vous aurezbesoin dans d'autres domaines de votrethème.
Ce code récupère lenom de la catégorie de l'article actuel,puis l'affiche sousforme de lien vers les articles répertoriés dans la catégorie via lefichier category.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>'; ?>
This is probably more than you need right now, but is probably something you will need on other areas of your theme.
This code gets the category name of the current post, then displays it as a link to the posts listed in the category via the category.php file.
<?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>'; ?>
Quandj'interroge la catégorie (category.php),comment obtenir letitre de la catégorie actuelle,c'est-à-dire celle quiestinterrogée?
Et comment obtenir letitre de labaliseet de la date (que ce soit lejour,lemois ou l'année)?