Home › Forum › Plugin e temi di WP › [theme]file.php per pagina specifica
-
AutorePost
-
-
20 Agosto 2008 alle 6:55 #7627lbottoniPartecipante
Ciao a tutti,
sto sviluppando per la prima volta un mio tema di WP, quello che cerco di fare e poter dire a wp che se si visualizza la pagina con ID=5 il file da caricare è miofile.php
è possibile?…se si, mi fate un esempio..
il mio SWorld
-
20 Agosto 2008 alle 7:09 #56932SteveAglAmministratore del forum
Suggerirei di leggere la gerarchia dei template e Usare le pagine:
http://www.wpitaly.it/wiki/Main/GerarchiaTemplate
http://www.wpitaly.it/wiki/Main/UtilizzarePagine
li c’è tutto quel che ti serve
-
20 Agosto 2008 alle 7:24 #56933lbottoniPartecipante
Grazie Steve, ma è da ieri che ci sono in quelle pagine e purtroppo non ho afferrato “il come” fare quello che mi serve…per questo mi sono rivolto al forum…mi puoi fare un esempio specifico del mio caso?
-
20 Agosto 2008 alle 8:13 #56939SteveAglAmministratore del forum
Crei un template di pagina con il codice che preferisci e lo assegni alla pagina che vuoi che usi quel template…
-
20 Agosto 2008 alle 8:24 #56940lbottoniPartecipante
ok, ti ringrazio Steve, ma l’aiuto richiesto era pratico e non teorico..quello dei template l’ho letto (ma non capito) per questo mi sono arreso e ho richiesto l’aiuto al forum…grazie lo stesso, cercherò aiuto altrove.
ciao
-
20 Agosto 2008 alle 8:51 #56941lbottoniPartecipante
ecco un modo x aggirare l’ostacolo.
nel div presente nella mia index.php del mio tema che dovrà contenere il testo delle pagine ho inserito nel loop un if per indicare che quella pagina specifica deve essere visualizzata con una speciale.
<div id=”content”>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?
if(is_page(“miofile”))
{include (“miofile.php”);}
?>
<?php endwhile; else: ?>
<?php _e(‘Sorry, no posts matched your criteria.’); ?>
<?php endif; ?>
</div>
il tag condizionale is_page() mi permette di passare come argomento il titolo della pagina o anche il suo id.
Magari non è la soluzione corretta, ma è almeno un punto da cui partire.Se avete suggerimento o correzioni, fatemele sapere.
Ciao a tutti.`
il mio SWorld
-
20 Agosto 2008 alle 9:32 #56942gollum1Partecipante
Il tuo metodo è corretto ed è l’unica soluzione se devi includere un file diverso a seconda della pagina, ma come ti è già stato suggerito, per queste cose generalmente si usano i template, che semplificano notevolmente la via…
sul wiki, alla ricerca di template hai tutte le info, ma eccoti un piccolo spunto di partenza…
1) Costruisci il tuo template (magari copiando index.php e integrando il codice che ti serve (il codice aggiunto dall’include per intenderci)
2) ricordati di inserire in testa al file le righe per identificarlo come template:
<?php
/*
Template Name: Nome del template
*/
?>
3) crei normalmente la tua pagina che dovrà usare il tuo template, come fai per tutte le pagine… solo che come pagina di template usi invece che quella di default, quella che hai creato tu…
il metodo di utilizzo è veramente molto semplice e versatile.
Byez
—
Gollum1
-
20 Agosto 2008 alle 9:45 #56943lbottoniPartecipante
grazie..leggevo, ma mi perdo in un bicchiere d’acqua..esempio, se ho capito bene, basterebbe:
1-creo il file myfile.php e lo salvo nella directory del tema
2-nel file inserisco ad esempio questo codice
<?
/*
Template Name: MioTemplate
*/
?>
<div id=”content”>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
HELLO WORLD!!!!!!
<?php endwhile; else: ?>
<?php _e(‘Sorry, no posts matched your criteria.’); ?>
<?php endif; ?>
</div>
3-poi quando dal pannello di wp creo una pagina, gli associo il template e “MioTemplate”
corretto?
il mio SWorld
-
20 Agosto 2008 alle 10:20 #56947gollum1Partecipante
a parte il fatto che non ti verrebbe scritto nessun post, perché nel loop non hai messo la funzione che richiama articoli o pagine (the_content() per intenderci o gli altri tag di visualizzazione), sଅ è corretto… praticamente ogni volta che apri quella pagina, ti rimangono sempre delle parti statiche che sono quelle che hai aggiunto tu (“HELLO WORLD”) immerse nelle parti dinamiche (se esistono, nel tuo caso per ora no).
In realtà , l’uso di un metodo piuttosto che un’altro dipende notevolmente da quello che realmente vuoi costruire… io uso i template quando voglio costruire la pagina in diversi modi in base alla tipologia di articolo che inserisco, o ancora più banalmente, per avere una pagina personalizzata in basa alla categoria dell’articolo.
Byez
—
Gollum1
-
20 Agosto 2008 alle 13:02 #56948lbottoniPartecipante
si..so che non ho metto il the_content(), ma era solo un esempio per comprenderne la logica. Mi premeva sapere e capire. Adesso è decisamente più chiaro.
Grazie di cuore
il mio SWorld
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.