2

私は以下のような機能を持っています

if(!function_exists('generate_share_urls')) {
  function generate_share_urls() {
      $title = the_title();
      $content = the_content();
    $share_urls = array (
      'facebook'      => 'http://www.facebook.com/sharer/sharer.php?u=',
      'twitter'       => 'http://twitter.com/share?url=',
      'google_plus'   => 'https://plus.google.com/share?url=',
      'linkedin'      => 'http://www.linkedin.com/shareArticle?mini=true&url=',
      'pinterest'     => 'http://pinterest.com/pin/create/button/?url=',
      'email'         => 'mailto:?subject={'.$title.'}&body='.$content.',
      'permalink'     => ''
   );
   return $share_urls;
  }
}

関数を実行すると、ページの $title と $content が見つかりません。私のコードに問題はありますか?

4

1 に答える 1

2

the_title()タイトル/コンテンツを出力the_content()しますが、返しません。代わりに必要なのは次の関数です。get_

if(!function_exists('generate_share_urls')) {
  function generate_share_urls() {
      $title = get_the_title();
      $content = get_the_content();
    $share_urls = array (
      'facebook'      => 'http://www.facebook.com/sharer/sharer.php?u=',
      'twitter'       => 'http://twitter.com/share?url=',
      'google_plus'   => 'https://plus.google.com/share?url=',
      'linkedin'      => 'http://www.linkedin.com/shareArticle?mini=true&url=',
      'pinterest'     => 'http://pinterest.com/pin/create/button/?url=',
      'email'         => 'mailto:?subject={'.$title.'}&body='.$content.',
      'permalink'     => ''
   );
   return $share_urls;
  }
}
于 2013-01-14T08:00:17.407 に答える