WordPress – fa titlul unui articol link extern

Ai dorit vreodata sa pui linkul de la titlul articolui tau spre un alt site? Daca da.. atunci ai venit unde trebuie.

Tot ce trebuie sa faci este sa adaugi urmatorul cod in fisierul functions.php:

[php]
function print_post_title() {

global $post;

$thePostID = $post->ID;

$post_id = get_post($thePostID);

$title = $post_id->post_title;

$perm = get_permalink($post_id);

$post_keys = array(); $post_val = array();

$post_keys = get_post_custom_keys($thePostID);

if (!empty($post_keys)) {

foreach ($post_keys as $pkey) {

if ($pkey==’title_url’) {

$post_val = get_post_custom_values($pkey);

}

}

if (empty($post_val)) {

$link = $perm;

} else {

$link = $post_val[0];

}

} else {

$link = $perm;

}

echo ‘<h2><a href="’.$link.’" rel="bookmark" title="’.$title.’">’.$title.'</a></h2>’;

}
[/php]

Dupa ce ai facut acest aspect trebuie sa modifici peste tot unde apare <?php the_permalink() ?> cu <?php print_post_title() ?>.

Acum cand doresti sa faci acest lucru trebuie sa adaugi un camp cu numele title_url

Spune si tu parerea...