需要自定义短代码

时间:2016-09-22 02:48:03

标签: wordpress attachment shortcode

// Image shortcode
function shortcode_image( $atts = array(), $content = null) {
    $atts = $this->attributefix( $atts );

    // [img="Google's Favicon"]http://www.google.com/favicon.ico[/img]
    if ( isset($atts[0]) ) {
        $alt = $atts[0];        //Google's Favicon
        $img = $content;        //http://www.google.com/favicon.ico
        return '<img src="' . $img . '" alt="' . do_shortcode( $alt )  . '" />';
    }
    // [img]http://www.google.com/favicon.ico[/img]
    else {
        $img = $content;
        return '<img src="' . $img . '" />';
    }
}

通过这个简短的代码当我把它放在我的帖子中我可以看到图像 [IMG]的http:// *本地主机/ WordPress的/可湿性粉剂内容/上传/ 2016/09 / 57e2008e828da.jpg [/ IMG]

但我希望像这样显示我的图像

[IMG] 215 [/ IMG]

注意:215图片ID号

我该怎么做?

这可能吗?

1 个答案:

答案 0 :(得分:2)

对于这个,您可以使用wp_get_attachment_url()并传递附件ID来获取url,我已经使用wp_get_attachment_url()对您的函数进行了一些修改。

import * as Rx from "rxjs/Rx";

let set = Rx.Observable.combineLatest(

    // Combine the latest values from set1 and set2
    // using AngularFire2 object observables.

    this.af.database.object('/set1/'),
    this.af.database.object('/set2/'),

    // Use the operator's project function to emit an
    // object containing the required values.

    (set1, set2) => {
        let result = {};
        Object.keys(set1).forEach((key) => {
            if (!set2[key]) {
                result[key] = set1[key];
            }
        });
        return result;
    }
);

set.subscribe((set) => { console.log(set); });