最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

variables - Get current page id, title, url, etc

programmeradmin4浏览0评论

Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible?

<a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&amp;body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a>

Where CURRENT_BLOG_NAME is ??? and CURRENT_PAGE_TITLE is ???

WP_PLUGIN_URL.$_SERVER['REQUEST_URI'] does get me the path to the current page.

Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible?

<a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&amp;body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a>

Where CURRENT_BLOG_NAME is ??? and CURRENT_PAGE_TITLE is ???

WP_PLUGIN_URL.$_SERVER['REQUEST_URI'] does get me the path to the current page.

Share Improve this question asked Aug 10, 2011 at 17:13 JohnnyBizzleJohnnyBizzle 4433 gold badges8 silver badges17 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1
<?php
$link = 'mailto:?subject='. get_bloginfo() .' '. the_title_attribute(array('echo'=>0));
$link .= '&amp;body=some text '. get_permalink();
?>
<a href="<?php echo $link ?>">mail to a friend</a>

There's the wp_mail($to, $subject, $message, $headers, $attachments); function for such things.

Furthermore there's a function called get_permalink();. And another one called get_the_title();.

You can combine them in a function:

function wpse25552_mail_permalink()
{
    global $post;
    $post_id = $post->ID;

    $title = get_the_title( $post_id );
    $subject = sprintf( __('I want to share %1$s with you', YOUR_TEXTDOMAIN ), $title );

    $permalink = get_permalink( $post_id );
    $message = sprintf( __("Yo! Look what I've found here: %1$s", YOUR_TEXTDOMAIN), $permalink );

    // ... stuff for $to, $subject, etc.

    wp_mail($to, $subject, $message, $headers, $attachments);
}

Note, that you have to replace YOUR_TEXTDOMAIN with your themes textdomain string. Else you can leave it out (don't forget to delete the comma too).

发布评论

评论列表(0)

  1. 暂无评论