Obține titlul postării cu link

15 apr. 2014, 13:53:56
Vizualizări: 14.2K
Voturi: 3

Folosesc acest cod pentru a trimite un e-mail din site-ul meu WordPress. Acesta trimite permalink-urile postărilor. Cum pot modifica acest cod pentru a avea titluri cu link în loc de simple permalink-uri?

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);
                    $title = get_the_title($id); // Obține titlul postării
                    $links .= '<a href="' . $link . '">' . $title . '</a> <br>'; // Adaugă titlul cu link
                }
                //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('ehmudroy@gmail.com', 'New project notification', $link);
                //wp_mail('lijb@stunningtech.com', 'New project notification', $message, $headers);
                wp_mail($email, 'New project notification', $message, $headers);
            }
0
Toate răspunsurile la întrebare 1
2

Ai folosit așa cum este??

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

pentru a folosi asta

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

Încearcă să folosești asta în timp ce îți codez codul.

15 apr. 2014 14:18:40
Comentarii

Ai avut ocazia?

yeshansachithak yeshansachithak
15 apr. 2014 14:41:47

@Ahmad Bravo. Să ai o zi bună. :-) :-D :-)

yeshansachithak yeshansachithak
16 apr. 2014 07:40:01