Visualizzazione 2 filoni di risposte
Visualizzazione 2 filoni di risposte
- Devi essere connesso per rispondere a questo topic.
Email: info@wpitaly.it
Home › Forum › Problemi Vari con WP › Definire delle variabili e riutilizzarle in un tema
Salve a tutti. Sti realizzando un tema per WP e ho il seguente problema.
Visualizzo tramite query un post ma voglio mantenere il suo permalink anche all’esterno dei tag di query, in un’altra parte della pagina. Di conseguenza ho pensato di poter assegnare, subito dopo aver fatto la query, il permalink ad una variabile, che poi avrei potuto riutilizzare in qualsiasi altra parte della pagina. In semplice php non ci sarebbero stati problemi ma in WP qualcosa non va.
Ecco come procedo.
<?php query_posts(‘showposts=1&offset=1’); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $link1=the_permalink() ;?>
la variabile $link1 conterrà quindi il permalink.
Poi, quando mi serve richiamare il link al permalink, scrivo:
< a href="<?php echo"$link1" ?>">CONTINUA
Ottengo tutt'altro. Noto che la variabile contiene effettivamente il permalink, ma questo viene scritto in un'altra posizione apparentemente a caso.
Aiuto?
Sicuro che la variabile contenga il valore? Perchè the_permalink() non restituisce un link ma fa il dispaly di un link quindi fa un echo del valore….
Una funzione che restituisce un valore anzichè mostrarlo è get_permalink:
http://codex.wordpress.org/Template_Tags/get_permalink
Se usato all’interno del loop senza specificare un ID restituisce il permalink dell’articolo corrente.
Hai ragione grazie!
WPItaly - Copyright Creative Commons: CC BY-NC-SA 4.0