用超链接将此自定义字段换行

时间:2014-08-29 作者:user2802110

只是按照教程从头创建了一个自定义字段。我有一个网站链接字段。目前它只输出原始文本,没有链接。

那么,如何使此代码超链接:

<li><strong>Website:</strong> \'.$_imd_portfolio_website_output.\'</li>
完整代码:

function imd_portfolio_meta_box() {
    global $post;
    // get the custom field values as an array
    $values = get_post_custom( $post->ID );
    // extract the members of the $values array to their own variables (which you can see below, in the HTML code)
    extract( $values, EXTR_SKIP );

    // escape the output, just in case
    $allowed_html = array(
        \'a\' => array(
            \'href\' => array(),
            \'title\' => array()
        ),
        \'em\' => array(),
        \'strong\' => array()
    );
    $_imd_portfolio_details_output = wp_kses($_imd_portfolio_details[0], $allowed_html);
    $_imd_portfolio_client_output = wp_kses($_imd_portfolio_client[0], $allowed_html);
    $_imd_portfolio_website_output = wp_kses($_imd_portfolio_website[0], $allowed_html);
    $_imd_portfolio_quote_output = wp_kses($_imd_portfolio_quote[0], $allowed_html);
    $output = \'<div class="review-box">
        <ul class="review-box-list">
            <li><strong>Details:</strong> \'.$_imd_portfolio_details_output.\'</li>
            <li><strong>Client:</strong> \'.$_imd_portfolio_client_output.\'</li>
            <li><strong>Website:</strong> \'.$_imd_portfolio_website_output.\'</li>
            <li><strong>Quote:</strong>\'.$_imd_portfolio_quote_output.\'></li>
        </ul>
    </div>\';
    return $output;
}
更新:问题已解决我已编辑代码;更改此行-

<li><strong>Website:</strong> \'.$_imd_portfolio_website_output.\'</li>
到该行-

<li><strong>Website:</strong><a href="http://\'.$_imd_portfolio_website_output.\'">\'.$_imd_portfolio_website_output.\'</a></li>
谢谢大家的帮助

1 个回复
SO网友:Girija Sankar Dash

您可以通过验证和包装锚标记来实现这一点。首先检查在输入中,哪个用户给定了任何前缀,如http://www 或者不是。如果用户没有给出,则在输入中添加前缀,并将其放置在href 锚定标记的属性。我想它会成功的

结束

相关推荐