Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I got social bookmarks in jQuery, but how can I get post titles and permalinks in this snippet? If I put <?php echo get_permalink(); ?> in there, the whole site gets blank.

$('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=' + title + '%20-%20' + title);

UPDATE:

Here's the whole jQuery for the 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>
share|improve this question
    
The line you've posted is Javascript(or more specifically jQuery), you can't just nest PHP inside a Javascript file. The only time you can put PHP inside JS is when you're outputting that JS from inside a PHP file, is that the case? –  t31os Apr 2 '11 at 13:40
    
I got a link assigned to each post in PHP and when that link is hovered it opens a box with the bookmarking links. I'm not too familiar with jQuery (as you can see), so I though it could be that easy. –  Andrew Apr 2 '11 at 14:32
    
Andrew, if you post up the code you're working with someone(perhaps myself) might be able to offer a suggestion or two, but without seeing more of the associated code it's hard to say if what you're asking is possible. –  t31os Apr 2 '11 at 16:59
    
You're right, so I added the jQuery code in the original question and the PHP is like this if it helps any: <li><a href="#" rel="shareit-posterous" class="shareit-sm"><img src="<?php bloginfo('template_url'); ?>/images/posterous_16.png" width="16" height="16" alt="Posterous" title="Posterous" /></a></li> –  Andrew Apr 3 '11 at 8:58
    
Sorry Andrew, i was actually referring to the PHP code you're working with.. –  t31os Apr 3 '11 at 22:31

1 Answer 1

up vote 1 down vote accepted

You must output the propper HTML to make it working.

Specifically, the href-attribute needs to contain the URL and the title separated with the | sign, like <a href="http://example.com/post-url|post-title" rel="shareit" ....

That will enable the script you've posted above use a concrete URL and title.

As I don't know you PHP code from your theme I can not give any further hints on how to output the correct URL or title, but probably <?php the_permalink(); ?>|<?php the_title(); ?> might do it.

Take care, encodings do apply.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.