Home › Forum › Problemi Vari con WP › SHORTCODE problema di priorità
-
AutorePost
-
-
18 Giugno 2012 alle 16:43 #21932NappaPartecipante
Ciao,
ho creato un shortcode che prende tutte le immagini allegate nel post (non inserite nel testo) e genera una gallery (diventa molto comodo quando a un cliente devi far vedere come inserire una nuova foto nella gallery ).
Il problema è questo:
nel post io scrivo del testo e poi sotto, inserisco il mio shortcode [ customgallery ].
Quindi, testo prima, shortcode dopo.
Quando visualizzo la pagina, prima mi compare la gallery e poi il testo.
Ho anche verificato che non fosse un problema di CSS, ma nel codice generato, prima c’e’ la galley e poi il content.
C’e’ qualche possibilità che lo shortcode venga prima dei contenuti?
Grazie
-
19 Giugno 2012 alle 11:28 #96176adefaveriPartecipante
Può essere che la funzione associata al tuo shortcode faccia degli echo? il codice generato deve essere ritornato (ti crei man mano la stringa nella funzione e alla fine la restituisci con return).
Altrimenti, prova a postare il codice..
-
19 Giugno 2012 alle 11:30 #96177wollyAmministratore del forum
When the_content is displayed, the shortcode API will parse any registered shortcodes such as “[myshortcode]”, separate and parse the attributes and content, if any, and pass them the corresponding shortcode handler function. Any string returned (not echoed) by the shortcode handler will be inserted into the post body in place of the shortcode itself.
-
19 Giugno 2012 alle 13:26 #96179NappaPartecipante
Holà !
in effetti il problema è proprio quello…
facevo un echo dalla funzione, adesso faccio un return e funziona perfettamente…
Grazie 1000
posto il codice:
// [CUSTOM GALLERY]
function cusgall_func() {
global $post;
$size = ‘thumb-galleria’;
$limit = ‘0’;
$offset = ‘0’;
$images = get_children( array(‘post_parent’ => $post->ID, ‘post_status’ =>
‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’,
‘orderby’ => ‘menu_order ID’) );
if ($images) {
$num_of_images = count($images);
if ($offset > 0) : $start = $offset–; else : $start = 0; endif;
if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images;
endif;
$galleria = “<div class=’gallery’>”;
foreach ($images as $image) {
$img_title = $image->post_title; // title.
$img_description = $image->post_content; // description.
$img_caption = $image->post_excerpt; // caption.
$img_url = wp_get_attachment_url($image->ID); // url of the full size image.
$preview_array = image_downsize( $image->ID, $size );
$img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
///////////////////////////////////////////////////////////
// This is where you’d create your custom image/link/whatever tag using the variables above.
// This is an example of a basic image tag using this method.
};
$galleria = $galleria.”</div>”;
};
return $galleria;
}
add_shortcode(‘customgallery’, ‘cusgall_func’);
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.