SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use 'the_permalink()' in a mailto statement?

    Hi,
    I need to build a general purpose 'Send to a friend' button to be placed
    on almost every post on my sites.
    I was thinking of using 'the_permalink()' and 'the_title()' functions but I don't know how.
    Does anybody have any experiance with this?
    Thanks in advance for any help I can get.

  2. #2
    SitePoint Guru bronze trophy TheRaptor's Avatar
    Join Date
    Jul 2011
    Location
    New York
    Posts
    710
    Mentioned
    40 Post(s)
    Tagged
    0 Thread(s)
    You would do something like this:

    HTML Code:
    <a class="send-to-friend" href="mailto:?subject=Look at what I found on the net&BODY=This is a really cool article, you should check it out friend.<?php the_permalink(); ?>">Button Text</a>
    Basically you just use a plain mailto and inject "the_permalink();" function call into it. And if you wanted this to appear in all your posts, then you'd put this snippet in the single.php file.
    TheRaptor - Joe

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand why the code must be in the single.php.

  4. #4
    SitePoint Guru bronze trophy TheRaptor's Avatar
    Join Date
    Jul 2011
    Location
    New York
    Posts
    710
    Mentioned
    40 Post(s)
    Tagged
    0 Thread(s)
    It only has to be in your single.php file if you need a button in every post you create. Another important thing to remember is, the_permalink() only works inside the main loop.
    TheRaptor - Joe

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TheRaptor View Post
    It only has to be in your single.php file if you need a button in every post you create. Another important thing to remember is, the_permalink() only works inside the main loop.
    OK, now I see your point and you are right.
    I have three such loops and that will not be a problem.
    Not all post will have this button and the criteria is not 'according' to any logic.
    I was thinking maybe there is a way to place the mailto (a generic formula) into
    each and every post needed (about 70%) and then, when mooving the post to
    archive, remove that button. Maybe I need a 'flag' about that button.
    What do you think?

  6. #6
    SitePoint Guru bronze trophy TheRaptor's Avatar
    Join Date
    Jul 2011
    Location
    New York
    Posts
    710
    Mentioned
    40 Post(s)
    Tagged
    0 Thread(s)
    If the vast majority of your posts will have this button and only a select number will not then you could use CSS to hide the button on those posts where you don't need it (based on the custom post id). For example:

    Code CSS:
    #post_114 .send-to-friend,
    #post_118 .send-to-friend
     { display: none; }
    TheRaptor - Joe

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK Sir! It works, thanks to you.
    A really appreciate your help in this.
    Have a good one.

  8. #8
    SitePoint Guru bronze trophy TheRaptor's Avatar
    Join Date
    Jul 2011
    Location
    New York
    Posts
    710
    Mentioned
    40 Post(s)
    Tagged
    0 Thread(s)
    Your welcome. Glad you got it working.
    TheRaptor - Joe


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •