下面是我用来向我设置的帖子类型添加自定义字段的代码。正如您所见,它创建了一个输入框,允许我添加任何我想要的内容。我想把URL放在这个框中(不带“http://”,例如“example.com”),并让它们可以自动点击。有办法吗?
add_action("admin_init", "add_friends_fields");
function add_friends_fields(){
add_meta_box("artist_links", "Links", "artist_links", "friends", "normal", "low");
}
function artist_links(){
global $post;
$custom = get_post_custom($post->ID);
$artist_links = $custom["artist_links"][0];
?>
<label>Links:</label><br /><br />
<input size="50" name="artist_links" value="<?php echo $artist_links; ?>" />
<?php
}
-编辑-
<section id="artists">
<h2 class="title"><span>Artists</span></h2>
<?php
$i=1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(\'post_type=friends&posts_per_page=-1\');
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$custom = get_post_custom($post->ID);
$artist_links = $custom["artist_links"][0];
$artist_bio = $custom["artist_bio"][0];
?>
<article class="mgm-artist<?php if($i%6 == 0) { echo \' right\'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'video-thumb\' ); } ?>
<section class="artist-details">
<p><span>Name:</span> <?php the_title(); ?></p>
<p><span>Bio:</span> <?=$artist_bio?></p>
<p><span>Link(s):</span> <?=$artist_links?></p>
</section>
</article>
<?php
endwhile;
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
</section>
最合适的回答,由SO网友:wyrfel 整理而成
把这个放在你的函数中。php:
function my_format_artist_links($urls) {
$urls = explode(\',\', $urls);
$links = array();
foreach ($urls as $url) {
if (empty($url)) continue;
$links[] = \'<a href="http://\'.$url.\'">\'.$url.\'</a>\';
}
return implode(\',\', $links);
}
然后替换
<p><span>Link(s):</span> <?=$artist_links?></p>
使用
<p><span>Link(s):</span> <?php echo my_format_artists_links($artist_links); ?></p>\'