2012-04-20 5 views
6

Próbuję znaleźć krótki kod, który pozwoli mi dodać "Pin It" (Pinterest), link tekstowy do mojego bloga. Chcę tylko link tekstowy. Nie chcę używać przycisku graficznego, pod który podają kod, co sprawia, że ​​jest to trudne.Pinterest "Pin it" krótki kod tylko do linku tekstowego w blogu wordpress

Jest to bardzo proste w przypadku Facebooka i Twittera. Na przykład:

<a href="http://www.facebook.com/share.php?u=<?php echo get_permalink() ?>" title="Share on Facebook" target="_blank">Facebook,</a> 

<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Share on Twitter" target="_blank">Twitter,</a> 

Czy ktoś wie, jak korzystać z podobnej linii kodu na Pinterest? Wszelkie wskazówki są mile widziane.

Odpowiedz

0

jeśli przyjrzeć the generated button:

Jest takie <img> tag:

Może to jest to, co chcesz:

<a href="http://pinterest.com/pin/create/button/" class="pin-it-button" count-layout="horizontal">pin it!</a> 

A oto jak to zrobić za pomocą kod serwera:

<a href="http://pinterest.com/pin/create/button/?url={the URL you want to pin}&media={image URL assiciated to the URL}&description={image or URL description}" class="pin-it-button" count-layout="horizontal">pin it!</a> 
+0

Nie sądzę, że to działa. Wygenerowany kod przycisku prosi mnie o podanie adresu URL i nazwy obrazu. Jednak potrzebuję kodu, który po prostu wyciągnie te informacje ze strony za pomocą php, jak te na Facebooku i Twitterze. – Glyph

+0

przeczytaj moją zaktualizowaną odpowiedź – ariefbayu

+0

Próbowałem tego również, ale zmusza grafikę przycisku do wyświetlenia.Próbowałem utworzyć niestandardową klasę dla przycisku pin-it, aby ją ukryć, ale nadal nie ma miłości. Z pewnością nie jest tak trudno pokazać tylko link tekstowy? – Glyph

3

To jest to, co zrobiłem na mojej stronie.

/*Stuff for Pinterest*/ 
    //getting the permalink 
$postpermalink = urlencode(get_permalink()); 

    //getting the thumbnail 
$imageurl = urlencode(wp_get_attachment_url(get_post_thumbnail_id($post->ID))); 
/*End of Pinterest*/ 

Następnie html:

<a target="blank" href="http://pinterest.com/pin/create/button/?url=<?php echo $postpermalink ?>&media=<?php echo $imageurl ?>" title="Pin This Post">Pin</a> 

Nadzieja to pomaga.

1

Można użyć podobnego podejścia w następujący sposób:

<a target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&amp;media=<?php echo $image->guid;?>&amp;description=<?php echo rawurlencode(get_the_title()); ?>">Pinterest,</a> 

Przykład HTML:

<a target="_blank" href="http://pinterest.com/pin/create/button/?url=http://www.google.&amp;media=http://www.google.co.id/images/srpr/logo3w.png&amp;description=Google Search Engine" >Pinterest,</a> 
0

Konwersja odpowiedź @AllanT w SHORTCODE.

Zastosowanie: [pinterest-link title="HREF TITLE" text="ANCHOR TEXT"]
atrybuty title i text są opcjonalne.

add_shortcode('pinterest-link', 'so_10240032_pinterest_text_link'); 

function so_10240032_pinterest_text_link($atts, $content = null) 
{ 
    $title = (isset($atts['title'])) ? $atts['title'] : 'Pin This Post'; 
    $text = (isset($atts['text'])) ? $atts['text'] : 'Pin'; 

    $postpermalink = urlencode(get_permalink()); 

    $imageurl = urlencode( 
     wp_get_attachment_url( 
      get_post_thumbnail_id($post->ID) 
     ) 
    ); 

    $html = 
     '<a target="blank" href="http://pinterest.com/pin/create/button/?url=' 
     . $postpermalink 
     . '&media=' 
     . $imageurl 
     . '" title="' 
     . $title 
     . '">' 
     . $text 
     . '</a>'; 

    return $html; 
} 
2

używam: (source)

w function.php:

function pinterest_post_page_pin_no_count() { 
    global $post; 
    /* HORIZONTAL NO-COUNTER PINTEREST BUTTON */ 
    printf('<div class="pinterest-posts"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="none">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode(get_permalink()), urlencode(get_post_meta($post->ID, 'thesis_post_image', true))); 
    } 
    add_shortcode('thesis_hook_before_post_box', 'pinterest_post_page_pin_no_count'); 

w% nazwa-szablonu% .php

<?php echo do_shortcode("[thesis_hook_before_post_box]"); ?> 

lub po prostu (source)

<a href="http://www.pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php if(function_exists('the_post_thumbnail')) echo wp_get_attachment_url(get_post_thumbnail_id()); ?>&description=<?php echo get_the_title(); ?> - <?php echo get_permalink(); ?>" id="pinterest" target="_blank">Pinterest Pin It</a> 
Powiązane problemy