我写了这两个函数,它们替换了一个分解的自定义字段字符串和post固定链接:
(其中自定义字段应如下所示:Google++http//:google.com")
// Custom Permalink
function custom_permalink($url){
global $post;
$link = get_post_meta($post->ID,'link',true);
if ($link) {
$pieces = explode("++", $link);
$url = $pieces[1];
} else {
$url = the_permalink();
}
return $url;
}
// Via Text
function via_text($url){
global $post;
$link = get_post_meta($post->ID,'link',true);
if ($link) {
$pieces = explode("++", $link);
$url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
} else {
$url = ' ';
}
return $url;
}..。它们在MAMP服务器上测试时工作得很好,但在部署时会返回:
“警告:缺少参数1”
你知道为什么会发生这种事吗?
发布于 2012-08-28 19:15:46
好的..。我想通了..。当一个类被实例化,并且构造函数没有默认参数时,就会发生这种情况。
以下是工作函数。
// Custom Permalink
function custom_permalink($url='') {
global $post;
$link = get_post_meta($post->ID,'link',true);
if ($link) {
$pieces = explode("++", $link);
$url = $pieces[1];
} else {
$url = the_permalink();
}
return $url;
}
// Via Text
function via_text($url='') {
global $post;
$link = get_post_meta($post->ID,'link',true);
if ($link) {
$pieces = explode("++", $link);
$url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
} else {
$url = ' ';
}
return $url;
}以防有人需要帮助。它们的用途:
如果有一个带有自定义字段‘链接’的帖子(如: Google++http://google.com),该函数将用自定义链接替换固定链接。所以在主题调用中: echo custom_permalink();...代替the_permalink();
via_text()函数的工作方式略有不同;它使用自定义字段'link‘展开调用span标记,如下所示:
<span><a href="http://google.com">Via Google</a></span>希望这对其他人也有效
:)
https://stackoverflow.com/questions/12150600
复制相似问题