Home › Forum › Problemi Vari con WP › Piccolo aiuto su shortcode per Google Plus One
-
AutorePost
-
-
3 Agosto 2011 alle 7:29 #18763sandrinoPartecipante
Ciao ragazzi,
avrei bisogno di un piccolo aiuto da chi conosce il php.
Ho implementato il pulsante google +1 attraverso uno shortcode (i plugin esistenti non mi piacciono) da inserire negli ARTICOLI (nelle PAGINE l’ho impostato fisso a livello di codice).
Nel function.php ho quindi inserito il seguente codice:
<?php
function plusone() {
return '
<div class="plusarticle"> <g:plusone href="<?php echo get_permalink(); ?>" size="tall"> </g:plusone> </div>
'; }
add_shortcode('plus1', 'plusone');
?>
Quando lo vado a richiamare attraverso lo shortcode, nell'html dell' articolo mi viene tradotto in:
<div class="plusarticle"> <g:plusone href="<?php echo get_permalink(); ?>" size="tall"> </g:plusone></div>
quindi invece di mettermi l'url della pagina mi compare la scritta "<?php echo get_permalink(); ?>".
Di sicuro mancherà qualcosa nel codice php inserito nel function, ma io non me ne intendo di php.
Voi riuscite ad aiutarmi?
Grazie mille. -
3 Agosto 2011 alle 8:24 #87151AndreamkPartecipante
Per forza.
con <?php apri l’interprete php con ?> lo chiudi.
Quello che c’è fuori da quei simboli viene messo a video cosi com’è e in genere è html.
Detto questo tu inizi aprendo l’interprete php poi dentro la funzione fai tornare una stringa in cui all’interno c’è un apertura e chiusura con funzione annessa.
Ma questo dall’interprete non viene assolutamente considerato perchè per lui quello è tutto testo.
Quel codice andrebbe bene se fossi fuori da php.
Quindi devi fare
<?php
function plusone() {
return ‘<div class=”plusarticle”> <g:plusone href=”‘.get_permalink().'” size=”tall”> </g:plusone> </div>’;
}
add_shortcode(‘plus1’, ‘plusone’);
?>
Ciao
Andrea
-
3 Agosto 2011 alle 8:51 #87156sandrinoPartecipante
Grazie MILLLLLLEEEEE!!!
Anche per la spiegazione
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.