Règles de réécriture personnalisées pour les flux de requêtes personnalisées (chaînes de requête query_var dans l'URL)?
1 réponses
- votes
Vouspouvez utiliser add_rewrite_rule
accroché à la init
,au lieu d'utiliser l'action generate_rewrite_rules
filtre (où il devient unpeubas ).
Mais le vraiproblème avec vos règles de réécritureest le regexen place. Voici à quoi cela ressemblerait:
function wtnerd_edition_specific_categories() {
add_rewrite_rule( '(.+?)/channel/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&paged=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&paged=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]', 'top' );
}
add_action( 'init', 'wtnerd_edition_specific_categories' );
Vouspouvez également utiliser le crochet defiltre rewrite_rules_array
.
You can use add_rewrite_rule
hooked to the init
action, instead of using the generate_rewrite_rules
filter (where it gets a bit low-level).
But the actual problem with your rewrite rules is the regex in place. Here's what it'd look like:
function wtnerd_edition_specific_categories() {
add_rewrite_rule( '(.+?)/channel/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&paged=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/channel/(.+?)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&paged=$matches[3]', 'top' );
add_rewrite_rule( '(.+?)/section/(.+?)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]', 'top' );
}
add_action( 'init', 'wtnerd_edition_specific_categories' );
You can also use rewrite_rules_array
filter hook.
Questionmise àjour.
Ce quej'essaie defaire
Sije souhaite afficher des articles (ou unflux d'articles) qui appartiennent à une catégorie ET unetaxonomiepersonnalisée,ou une catégorie ET unebalise,ou unetaxonomiepersonnalisée ET unebalise,je peux lefaireen utilisant des variables de requête comme requête chaînes dans l'URL.
Maisje veux d'abordembellir les URL,comme ceci:
example.com/?category_name=main&channel=tech
àexample.com/main/channel/tech/
example.com/?category_name=main&channel=tech&feed=rss2
àexample.com/main/channel/tech/feed/
example.com/?category_name=main&tag=jsyk
àexample.com/main/tag/jsyk/
example.com/?category_name=main&tag=jsyk&feed=rss2
àexample.com/main/tag/jsyk/feed/
Où
category_name
définit le slug de catégorie,channel
le slug duterme detaxonomiepersonnalisée "Channel"ettag
le slug detag.Commentje fais
Tout d'abord,j'aiessayé de lire autant d'exemples quepossible,dont:
http://codex.wordpress.org/Class_Reference/WP_Rewrite
Besoin d'aide avec add_rewrite_rule
Besoin d'aidepour les URL conviviales dans Wordpress
Règles de réécriturepersonnaliséespour une requête $ _GET
type depublicationpersonnaliséet lienpermanent detaxonomiepersonnalisée
Permaliensbasés sur lataxonomie
Jeplacetoutes lesfonctionsindépendantes duthème demon site dans unpluginincontournable,qui ressemble à ceci:
C'est là quej'ai ajoutémafonction de réécriture qui ressemble à ceci:
Problème
Les URL defluxne fonctionnentpas. Parexemple:
charge lemodèle
content-none.php
au lieu d'afficher leflux réel des articles qui appartiennent auxditstermes.Jene saispas comment résoudre ceproblème.