Home › Forum › Problemi Vari con WP › template (o semplice nome) alternativo per i commenti di alcune pagine
-
AutorePost
-
-
6 Maggio 2008 alle 16:55 #6585essezetaPartecipante
Un saluto a tutti…
Volevo avere il vostro parere su questa mia necessità :
nel mio blog ho creato delle pagine con template personalizzato modificando semplicemente il link al css responsabile di ogni template di pagina…
in pratica dopo aver creato il temnplate di pagina MIApage.php ho sostituito
<?php get_header(); ?>
con
<?php include (‘MIOheader.php’); ?> che punta ad un css alternativo…
(ecco l’originale della soluzione che ho adottato);
Bene, tutto a posto, funziona alla grande…
Vorrei però fare una cosa del genere anche con i commenti…
Mi spiego, quando sono in una pagina che utilizza il template MIApage.php vorrei che i commenti fossero gestiti con un aspetto differente (preciso: ad esempio inserisco classi supplementari che cambino l’aspetto del titolo generale n° COMMENTI, oppure lo elimino del tutto e ci metto un testo fisso scelto da me: infatti più che altro ho bisogno che nelle pagine gestite da MIApage.php i commenti vengano chiamati CONTRIBUTI, ma se lo cambio nella localizzazione poi mi cambia globalmente, mentre io nelle altre pagine e nei post voglio mantenere COMMENTI).
Ho provato sostituendo
<?php comments_template() ?>
con
<?php include (‘MIEIcomments.php’); ?> che avevo modificato a mio piacere,
ma cosଠi commenti non me li vede… vedo solo la form per inserirli, ma poi non compaiono… se torno a <?php comments_template() ?> vedo tutto correttamente, anche quelli inseriti prima ma non visti (ovvero in realtà li ha inseriti).
Spero di essere stato chiaro…
Qualcuno ha qualche idea su come realizzare ciò che voglio? Chiamare i commenti CONTRIBUTI in alcuni tipi di pagina.
Anche un plugin… io ho provato a cercare tra i plugin per vedere se ce n’era qualcuno che permetteva di maneggiare i commenti, c’è tanta roba, ma niente che faccia al caso mio…
Grazie in aticipo a tutti…
-
6 Maggio 2008 alle 17:01 #53418SteveAglAmministratore del forum
Semplicemente NON usi il metodo fatto sino ad ora ma nell’header metti un tag condizionale is_page (vedi wiki per info) idem nel template dei commento dove appare la scritta commenti avrai un if che a seconda della pagina stamperà commenti o contributi, quindi un solo template dei commenti con if e tag condizionali per decidere cosa fare a seconda della pagina. Molto più semplice e molto più pulito.
-
6 Maggio 2008 alle 17:11 #53420essezetaPartecipante
SteveAgl sei sempre il primo a rispondere… GRAZIE!!!
Senti, ad intuito io c’ero già arrivato a quello che mi dici… ma credimi ci ho provato e ho fatto un gran casino… con cicli condizioni ecc. mi perdo…
Non è che quando ti avanzano 2 minuti mi “imboccheresti” (come si dice dalle mie parti) la procedura?
Tanto lo so che è una cosa da due minuti… ma io dimentico sempre qualche ; ” o gestisco illogicamente elseif e co…
Naturalmente io non me ne sto con le mani in mano… Io intanto ci riprovo da solo seguendo il tuo consiglio e posto quello che ho fatto, cosଠmagari mi correggi.
Grazie comunque
gnl
-
7 Maggio 2008 alle 17:27 #53457hanslukasPartecipante
Ho consultato il Wiki alla sezione dei Tag Condizionali e ho provato la dritta di SteveAgl, ma ottengo errore…
ecco i dettagli delle mie operazioni…
cosa sbaglio?
Qui comments.php genera la parola COMMENTI quando ci sono
31 <div id="comments-list" class="comments">
32 <h3><?php printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count) ?></h3>
Per fargli dire CONTRIBUTI in certe pagine ho provato a fare cosà¬
31 <div id="comments-list" class="comments">
32 <h3>
33 <?php if (is_page('17')) {
34 echo "Contributo";
35 } elseif (is_page('16')) {
36 echo "Contributo";
37 } else {
38 printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count)
39 }
40 ?>
41 </h3>
Ottengo questo errore
Parse error: syntax error, unexpected '}' in MIOBLOGwp-contentthemesMIOTEMAcomments.php on line 39
Qualche consiglio???
Grazie a tutti
g
-
7 Maggio 2008 alle 18:33 #53461SteveAglAmministratore del forum
Manca il punto e virgola alla fine della riga 38 le righe da 33 a 37 si semplificano con:
<?php if (is_page(array(42,16))) {
echo “Contributo”;
} else {
Passi ad is_page un array di valori che possono essere una serie di ID ma puoi anche specificare racchiudendo fra apici singoli anche l’abbreviazione di una pagina o il suo titolo.
http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
Comunque a parte il punto e virgola vedi che no è difficile, poi le ottimizzazioni si imparan col tempo.
-
7 Maggio 2008 alle 19:16 #53464hanslukasPartecipante
caxxo lo sapevo!!!!!
non ce l’ho fatta per un PUNTO E VIRGOLA…
A parte le stupidaggini,
GRAZIE MILLE SteveAgl
Preciso però che:
se inserisco il ; mancante funziona perfettamente…
Se semplifico con l’array invece non va…
non mi da alcun errore… però non compare CONTRIBUTO…
Per quello che dovevo ottenere io, va già bene il fatto che funzioni con il primo consiglio… però a vantaggio di chi leggerà forse è il caso di verificare perchè questa seconda sintassi non va…
anche perchè in realtà è più economica… basta inserire un ID in più separandolo con virgola…
Che cosa manca?
31 <div id="comments-list" class="comments">
32 <h3>
33 <?php if (is_page(array(17,16))) {
34 echo "Contributo";
35 } else {
36 printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count)
37 }
38 ?>
39 </h3>
Ad ogni modo,
un grazie a SteveAgl e un saluto a tutti...
g
-
7 Maggio 2008 alle 19:51 #53466SteveAglAmministratore del forum
non l’ho provato.. ho solo verificato non desse errori perchè ovviamente sul blog locale per questi test e prove non ho nulla una sola categoria etc…
Funziona però cosଠdire:
<?php if ( is_page(16) || is_page(17) ) {
|| è l’OR sempre da provare…
-
7 Maggio 2008 alle 20:57 #53469hanslukasPartecipante
Ottimo, l’ho appena testato…
funziona!
ps: ganzo l’OR !!!
Direi che possiamo fermarci…
Riassumendo, le versioni funzionanti sono queste due:
1.
<div id="comments-list" class="comments">
<h3>
<?php if (is_page('17')) {
echo "Contributo";
} elseif (is_page('16')) {
echo "Contributo";
} else {
printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count);
}
?>
</h3>
2.
<div id="comments-list" class="comments">
<h3>
<?php if ( is_page(16) || is_page(17) ) {
echo "Contributo";
} else {
printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count);
}
?>
</h3>
Buonanotte a tutti
g
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.