liens signet jquery
Question
Je suis dans les signets sociaux jQuery, mais comment puis-je obtenir des titres et permaliens poste dans cet extrait? Si je mets <?php echo get_permalink(); ?>
là-bas, tout le site est vide.
$('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=' + title + '%20-%20' + title);
Mise à jour:
Voici l'ensemble jQuery pour le bookmarking:
<script type="text/javascript">
jQuery(
function() {
//grab all the anchor tag with rel set to shareit
$('a[rel=shareit], #shareit-box').click(function(e) {
e.preventDefault();
//get the height, top and calculate the left value for the sharebox
var height = $(this).height();
var top = $(this).offset().top;
//get the left and find the center value
var left = $(this).offset().left + ($(this).width() /2) - ($('#shareit-box').width() / 2);
//grab the href value and explode the bar symbol to grab the url and title
//the content should be in this format url|title
var value = $(this).attr('href').split('|');
//assign the value to variables and encode it to url friendly
var field = value[0];
var url = encodeURIComponent(value[0]);
var title = encodeURIComponent(value[1]);
//assign the height for the header, so that the link is cover
$('#shareit-header').height(height);
//display the box
$('#shareit-box').show();
//set the position, the box should appear under the link and centered
$('#shareit-box').css({'top':top, 'left':left});
//assign the url to the textfield
$('#shareit-field').val(field);
//make the bookmark media open in new tab/window
$('a.shareit-sm').attr('target','_blank');
//Setup the bookmark media url and title
$('a[rel=shareit-mail]').attr('href', 'http://mailto:?subject=' + title);
$('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/share.php?u=' + url + '&title=' + title);
$('a[rel=shareit-posterous]').attr('href', 'http://posterous.com/share?linkto=' + url + '&title=' + title);
$('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=' + title + '%20-%20' + title);
});
//onmouse out hide the shareit box
$('#shareit-box').mouseleave(function () {
$('#shareit-field').val('');
$(this).hide();
});
//hightlight the textfield on click event
$('#shareit-field').click(function () {
$(this).select();
});
});
</script>
La solution
Vous devez sortir le propper HTML pour le faire fonctionner.
Plus précisément, l'attribut href doit contenir l'URL et le titre séparé avec le | signe, comme <a href="http://example.com/post-url|post-title" rel="shareit" ...
.
Cela permettra au script que vous avez posté ci-dessus utilisent une URL de béton et le titre.
Comme je le code PHP vous savez pas de votre thème Je ne peux pas donner d'autres indications sur la façon de sortie l'URL correcte ou le titre, mais probablement <?php the_permalink(); ?>|<?php the_title(); ?>
peut le faire.
Attention, encodages ne s'appliquent.