Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2010
    Messaggi
    302

    [Wordpress] Rendere Thumbnail linkabile

    Un saluto agli amici della community.

    Mi piacerebbe rendere "Linkabile" ai Post l'immagine Thumbnail presente sul mio sito blogomedia.it

    Mi dareste una mano ?
    Immagini allegate Immagini allegate
    Se volete che la funzione di un programma non venga scoperta dall'utente, descrivetela nella documentazione...

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    49
    Ciao,

    basta inserire la funzione the_title all'interno del codice che richiama il thumbnail.

    Se non hai capito inserisci qui la parte di codice che richiama la thumbnail del tuo tema !

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2010
    Messaggi
    302
    Ciao Mirko,
    grazie per la velocissima risposta.

    La parte di codice dovrebbe essere questa:

    codice:
    //$dim = ''; //if ($tipo=="thumbnail") 
    { $dim = 'width="150" height="150"'; 
    } 
    //if ($tipo=="small") 
    { $dim = 'width="65" height="65"'; 
    } 
    // Build the <img> string $sImgString = '' . '[img]' . $sUrl . '[/img]' . ''; 
    
    // Print the image echo $sImgString;
    Se volete che la funzione di un programma non venga scoperta dall'utente, descrivetela nella documentazione...

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    49
    Ciao,

    il codice che hai postato ti consente già di rendere linkabili le thumb, dovresti solo decommentarlo (togliere le ).

    Ti consiglio di provare a sostituire il codice che hai inserito con questo:

    codice:
     <?php if ( has_post_thumbnail()) : ?>    " >    <?php the_post_thumbnail( 'index', array('title' => ''.get_the_title().'' ));?>      <?php endif; ?>
    Poi vai nel foglio di stile css e inserisci questa regola qui:

    codice:
    img.attachment-index {width:65px; height:65px; float:left; display:block;}
    Dove 65px sta sia per l'altezza che la larghezza. Cambia questi valori a seconda di quanto vuoi sia grande la tua thumbnail.

    Fammi sapere

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2010
    Messaggi
    302
    Grazie al tuo prezioso aiuto sono riuscito a risolvere il problema del "Link".

    Ho aggiunto il codice css nel mio file style.css, il problema è che non sò dove inserire il codice php. Sappi che quello riportato precedentemente era solo un estratto di questo codice:

    Codice PHP:
    <?php //preso da WP Codex function postimage($size="thumbnail") { if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image',))) { foreach( $images as $image ) { $attachmenturl=wp_get_attachment_url($image->ID); $attachmentimage=wp_get_attachment_image( $image->ID, $size ); echo '[url="'.$attachmenturl.'"]'.$attachmentimage.'[/url]'; break; //una sola immagine stampata } } else { return; } } //Anteprima Immagine in fase di condivisione function set_default_image(){ global $post; $image = str_img_src($post->post_content); if($image != ""){ echo '<link rel="image_src" href="'. $image . '" />' . "\n"; } } add_action('wp_head', 'set_default_image'); function str_img_src($html) { if (strpos($html, '<img') !== false) { $imgsrc_regex = '#<\s*img [^\>]*src\s*=\s*(["\'])(.*?)\1#im'; preg_match($imgsrc_regex, $html, $matches); unset($imgsrc_regex); unset($html); if (is_array($matches) && !empty($matches)) { return $matches[2]; } else { return false; } } else { return false; } } function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); $content = strip_tags($content); if (strlen($_GET['p']) > 0) { echo "

    "; echo $content; echo "[url='"; the_permalink(); echo "']"."Read More &rarr;[/url]"; echo "</p>"; } else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) { $content = substr($content, 0, $espacio); $content = $content; echo "

    "; echo 
    $content; echo "..."; echo "[url='"; the_permalink(); echo "']".$more_link_text."[/url]"; echo "</p>"; } else { echo "

    "; echo 
    $content; echo "[url='"; the_permalink(); echo "']"."Read More &rarr;[/url]"; echo "</p>"; } } function bdw_get_images($post$tipo) { // Get the post ID $iPostID = $post->ID; // Get images for this post $arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID ); // If images exist for this page if($arrImages) { // Get array keys representing attached image numbers $arrKeys = array_keys($arrImages); /******BEGIN BUBBLE SORT BY MENU ORDER************ // Put all image objects into new array with standard numeric keys (new array only needed while we sort the keys) foreach($arrImages as $oImage) { $arrNewImages[] = $oImage; } // Bubble sort image object array by menu_order TODO: Turn this into std "sort-by" function in functions.php for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) { for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) { if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) { $oTemp = $arrNewImages[$j]$arrNewImages[$j] = $arrNewImages[$j + 1]; $arrNewImages[$j + 1] = $oTemp; } } } // Reset arrKeys array $arrKeys = array(); // Replace arrKeys with newly sorted object ids foreach($arrNewImages as $oNewImage) { $arrKeys[] = $oNewImage->ID; } ******END BUBBLE SORT BY MENU ORDER**************/ // Get the first image attachment $iNum = $arrKeys[0]; if ($tipo=="small" || $tipo=="thumbnail") { // Get the thumbnail url for the attachment $sUrl = wp_get_attachment_thumb_url($iNum); } else { // FULL SIZE IMAGE INSTEAD OF THE THUMBNAIL $sUrl = wp_get_attachment_url($iNum); } //$dim = ''; //if ($tipo=="thumbnail") { $dim = 'width="150" height="150"'; } //if ($tipo=="small") { $dim = 'width="65" height="65"'; } // Build the <img> string $sImgString = '[url="' . get_permalink() . '"]' . '[img]' . $sUrl . '[/img]' . '[/url]'; // Print the image echo $sImgString; } }
    Quale vantaggio ottengo se cambio il codice attuale con quello suggerito da te ?

    Se volete che la funzione di un programma non venga scoperta dall'utente, descrivetela nella documentazione...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.