Home › Forum › Plugin e temi di WP › hook and rewrite
-
AutorePost
-
-
29 Novembre 2010 alle 9:33 #15809testinawebPartecipante
sto scrivendo un plugin e mi servirebbe un aiuto:
premessa:
noi tutti sappiamo bene che se chiamo http://www.dominio.it/caretory/nomecategoria/ vado a finire sulla pagina del tema archive.php
se richiamo un articolo singolo vado a finire su single.php, con http://www.dominio.it/ vado a finire su l’index.php, ecc ecc
mio problema
io devo fare un hook per intercettare la chiamata ed inserire un nuovo tipo di pagina. es.: io voglio chiamare http://www.dominio.it/lista/nomelista e richiamare un file lista.php
qualcuno sa darmi condigli o parte di codice già scritto?
grazie in anticipo
buona giornata
m
-
29 Novembre 2010 alle 10:31 #79046SteveAglAmministratore del forum
creare un template di apagina con il codice desiderato, creare una pagona di nome nomelista con associato quel template di pagina… et voilà … senza dover fare modrewrite o altro…
-
29 Novembre 2010 alle 10:41 #79051testinawebPartecipante
in effetti ci avevo pensato, ma:
tutto quello che viene dopo “lista/” saranno variabili tipo: http://www.dominio.it/lista/var1/var2/var3/var4
la mia “pagina lista” deve essere in grado di ricevere la chiamata in ogni caso e mi sembra che il modrewrite di wordpress sia la soluzione… sbaglio?
-
29 Novembre 2010 alle 10:57 #79055SteveAglAmministratore del forum
ah si in questo caso si… direi che devi studiare qui:
-
29 Novembre 2010 alle 13:34 #79062testinawebPartecipante
ho scritto questo ma ancora arrivo sulla index.php e non so come far puntare ad un’altra pagina.
add_action(‘generate_rewrite_rules’, ‘add_rewrite_rules’);
add_filter(‘query_vars’, ‘query_vars’);
add_filter(‘init’,’flushRules’);
function add_rewrite_rules( $wp_rewrite ) {
$new_rules = array(‘list/(.+?)/?$’ => ‘index.php?list=$matches[1]’);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function query_vars($public_query_vars) {
$public_query_vars[] = “list”;
return $public_query_vars;
}
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
-
29 Novembre 2010 alle 13:42 #79063SteveAglAmministratore del forum
Se seugi il primo esempio del link che ti ho dato fa esattamente quello che chiedi traduce
http://mysite/project/1 in http://mysite/index.php?pagename=project&id=1
mettendo il nome che vuoi a project ed i paramentri al posto di id dovresti avere quello che ti serve… ovviamente nella riga:
$newrules
la regula expression dovrà essere opportunamente adattata per matchare il/i 1, 2, 3, enne parametri per poterli avere in $_REQUEST gestirli…
-
29 Novembre 2010 alle 14:01 #79067testinawebPartecipante
grazie mille, provo!
buona giornata
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.