Home › Forum › Problemi Vari con WP › template diverso solo per alcuni articoli. Possibile?
-
AutorePost
-
-
6 Febbraio 2011 alle 15:56 #16665je92Partecipante
Ciao. Vi spiego la mia esigenza. Vorrei dare la possibilità agli utenti di votare i post, ma non tutti, solo alcuni. Negli altri post non ho nessun bisogno di inserire le classiche stelline per il voto. Ma tutti i plugin che ho trovato richiedono un richiamo nel file single.php (e quindi compare in tutte gli articoli). Non ho trovato nessun plugin che utilizzi uno shortcode inseribile a piacere o valido solo per certe categorie.
Quindi ho pensato a questa soluzione: assegnare a questi articoli un template diverso(che conterrà il richiamo al plugin per il voto). Questo è possibile? Come? Oppure avete altre idee?
-
7 Febbraio 2011 alle 9:04 #81073SteveAglAmministratore del forum
e come li assegni ad un tempalte diverso? COn una categoria? Un campo personalizzato o cosa?
-
7 Febbraio 2011 alle 14:19 #81087je92Partecipante
Ma forse un campo personalizzato sarebbe il modo più comodo. Come dovrei fare in questo caso?
-
7 Febbraio 2011 alle 15:02 #81092SteveAglAmministratore del forum
fai una single che legge il campo personalizzato e se vale una cosa fa iun include di un file .php per quel tipo altrimenti include un file diverso…
il single attuale quindi si ridurrà a pochissime righe di codice che scelgono se includere un file o unaltro…
-
7 Febbraio 2011 alle 18:44 #81096je92Partecipante
Hai guide o esempi che potrei seguire, anche in inglese, per fare sta cosa?
-
7 Febbraio 2011 alle 20:10 #81099SteveAglAmministratore del forum
no è semplicissimo però, diciamo che prendi la single.php e crei due single identiche a questa di nome single-a.php e single-b.php diciamo che la a la tieni come è ora e la b è la versione che vuoi diversa.
a questo punto la single php originale diventerà una cosa del tipo:
global $post;
// Legge il campo personalizzato
$tipo_post = get_post_meta($post->ID, ‘tipopost’, true);
// Se è vuoto
if ( empty ($tipo_post) ) {
get_template_part(‘single’, ‘a’); // Carica single-a.php
} else {
get_template_part(‘single’, ‘b’); // Carica single-b.php
}
-
7 Febbraio 2011 alle 20:33 #81103je92Partecipante
Grazie mille! Gentilissimo
-
8 Marzo 2012 alle 12:35 #94228salwebPartecipante
Scusatemi riprendo questo post vecchio…
e se invece volessi fare in modo che il confronto nel file single.php non sia solo su vero o falso ma sul valore del campo personalizzato come faccio a modificare il codice?
-
8 Marzo 2012 alle 22:08 #94237salwebPartecipante
nessuno mi sa aiutare?
-
8 Marzo 2012 alle 22:08 #94238salwebPartecipante
-
9 Marzo 2012 alle 16:09 #94256Alt Design Web AgencyPartecipante
$tipo_post = get_post_meta($post->ID, ‘tipopost’, true);
Leggi il valore di $tipo_post e fai qualcosa di conseguenza.
Tipo:
if ($tipo_post == ‘valoreA’ ) {
get_template_part(‘single’, ‘a’); // Carica single-a.php
} else if ($tipo_post == ‘valoreB’){
get_template_part(‘single’, ‘b’); // Carica single-b.php
} else{
get_template_part(‘single’, ‘c’); // Carica single-c.php
}
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.