Comment obtenir le permalien d'un type de publication personnalisé?
4 réponses
- votes
-
- 2011-12-01
-
- 2011-10-25
Dans laboucle,vouspouvez simplement utiliser
the_permalink()
.En dehors de laboucle,vouspouvez utiliserget_permalink( $id )
.Within the loop, you can simply use
the_permalink()
. Outside of the loop, you can useget_permalink( $id )
.-
Cela renvoie lepermalien d'un article ou d'unepage spécifique.Je veux renvoyer lepermalien d'untype depublication.Ainsi,parexemple,s'ilexiste untype depublication appelé "critiques defilms"et que le lienpermanent de cetype depublicationest "www.website.com/movie-reviews",commentpuis-je obtenir cepermalien?Peut-être que cen'estpas un vraipermalientechniquement,je veuxjuste l'URL de cetype depublication.That returns the permalink of a specific post or page. I want to return the permalink of a post type. So, for instance, if there is a post type called "movie reviews", and the permalink of that post type is "www.website.com/movie-reviews", how do I get that permalink? Maybe this is not a true permalink technically, I just want the URL of that post type.
- 1
- 2011-10-25
- Industrial Themes
-
-
- 2012-07-30
Je sais que cemessageestpeut-être ancien,maisjuste au cas où quelqu'un d'autre chercherait lafonction quifait cela,voici celle quej'ai écrite. $post_type doit êtrepassé comme variable :)
if( !function_exists( 'wp_get_post_type_link' ) ){ function wp_get_post_type_link( &$post_type ){ global $wp_rewrite; if ( ! $post_type_obj = get_post_type_object( $post_type ) ) return false; if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { $struct = $post_type_obj->rewrite['slug'] ; if ( $post_type_obj->rewrite['with_front'] ) $struct = $wp_rewrite->front . $struct; else $struct = $wp_rewrite->root . $struct; $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); } else { $link = home_url( '?post_type=' . $post_type ); } return apply_filters( 'the_permalink', $link ); } }
J'espère que cela aide! :)
I know this post might be old but just in case someone else is searching the function that does this, here's the one i wrote. $post_type must be passed as a variable :)
if( !function_exists( 'wp_get_post_type_link' ) ){ function wp_get_post_type_link( &$post_type ){ global $wp_rewrite; if ( ! $post_type_obj = get_post_type_object( $post_type ) ) return false; if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { $struct = $post_type_obj->rewrite['slug'] ; if ( $post_type_obj->rewrite['with_front'] ) $struct = $wp_rewrite->front . $struct; else $struct = $wp_rewrite->root . $struct; $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); } else { $link = home_url( '?post_type=' . $post_type ); } return apply_filters( 'the_permalink', $link ); } }
Hope it helps ! :)
Jepeux obtenir le lienpermanent d'unebalise ou d'une catégorie depublication spécifique,mais quefaire sije veux obtenir le lienpermanent d'untype depublicationpersonnalisé?Jene trouve rien dans le Codex ou ailleurs sur lafaçon deprocéder.