
单击“自定义URL”以添加要添加到帖子标题的链接。现在您可以保存或发布您的帖子。
就这样。帖子标题现在将链接到您提供的自定义网址。
没有必要仅将其用于外部链接。您还可以使用它将用户发送到WordPress网站上的不同帖子和页面。
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 |
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=='external_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>';} |
|
1 |
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> |
|
1 |
<?php print_post_title() ?> |
您将在帖子编辑器下方找到自定义字段元框。
单击“Enter New”,然后external_url在“Name”字段中输入要添加到“ Value”字段中的帖子标题的URL 。
您现在可以保存或发布您的帖子。就是这样,您的帖子标题现在将链接到您在自定义字段中添加的URL。
下次需要添加链接时,只需external_url从下拉菜单中选择自定义字段,然后在值字段中输入外部链接。
我们希望本文能帮助您了解如何从WordPress中的帖子标题链接到外部链接。您可能还希望查看有关如何在WordPress网站上添加外部链接图标的指南。
原文:宁波网站开发设计