web-dev-qa-db-ja.com

リンク付きの投稿タイトルを取得

このコードを使って私のワードプレスサイトからEメールを送信しています。投稿のパーマリンクを送信します。パーマリンクだけでなくリンクされたタイトルを持つようにこれを編集する方法

if(count($ids) > 0){
                $user_id = $usermeta['user_id'];
                $userdata = get_userdata($user_id);
                $email = $userdata->data->user_email;
                //echo $email;
                $links = '';
                foreach($ids as $id){
                    $link = get_permalink($id);
                    $links .= $link . ' <br>';
                }
                //echo $links;

                if (have_posts()) : 
                    while (have_posts()) : 
                        the_post();
                        $emailTpl = get_the_content();
                    endwhile;
                endif;

                $message = preg_replace('/\[\%urls\%\]/', $links, $emailTpl);
                $headers = "MIME-Version: 1.0\n" . "Content-Type: text/html;"; 
                //wp_mail('[email protected]', 'New project notification', $link);
                //wp_mail('[email protected]', 'New project notification', $message, $headers);
                wp_mail($email, 'New project notification', $message, $headers);
            }
2
Allen

あなたはそのようにそれを使いましたか?

<a href="<?php get_permalink($id); ?>"><?php the_title($id); ?></a>

それに使用するため

foreach($ids as $id){
  $link = get_permalink($id);
  $title = get_the_title($id);
  $links .= '<a href="'.$link.'">'.$title.'</a>'.'<br/>' ;
  //$links .= $link . ' <br>';
}

get_permalink

get_the_title

私はあなたのコードをコーディングしている間それを使うようにしてください。

4
yeshansachithak