Wordpress中的自定义字段链接

时间:2018-06-01 22:12:51

标签: wordpress image function hyperlink customization

我在图片附件中有自定义字段。 我想在我的图库中插入自定义链接。 这是可正常工作的自定义字段代码。

            function my_image_attachment_fields_to_edit($form_fields, $post) {  
                $form_fields["custom1"] = array(  
                    "label" => __("Image Links To"),  
                    "input" => "text",
                    "value" => get_post_meta($post->ID, "_custom1", true)  
                );        
                return $form_fields;  
            }  

            function my_image_attachment_fields_to_save($post, $attachment) {    
                if( isset($attachment['custom1']) ){  
                    update_post_meta($post['ID'], '_custom1', $attachment['custom1']);  
                }  
                return $post;  
            }  

            add_filter("attachment_fields_to_edit", "my_image_attachment_fields_to_edit", null, 2); 
            add_filter("attachment_fields_to_save", "my_image_attachment_fields_to_save", null, 2); 




            function _save_attachment_url($post, $attachment) {
                if ( isset($attachment['url']) ) 
                    update_post_meta( $post['ID'], '_wp_attachment_url', esc_url_raw($attachment['url']) ); 
                return $post;
            }
            add_filter('attachment_fields_to_save', '_save_attachment_url', 10, 2);

            function _replace_attachment_url($form_fields, $post) {
                if ( isset($form_fields['url']['html']) ) {
                    $url = get_post_meta( $post->ID, '_wp_attachment_url', true );
                    if ( ! empty($url) )
                        $form_fields['url']['html'] = preg_replace( "/value='.*?'/", "value='$url'", $form_fields['url']['html'] );
                }
                return $form_fields;
            }
            add_filter('attachment_fields_to_edit', '_replace_attachment_url', 10, 2);

我想将链接放在我的函数文件的自定义库中。这是我的图库代码的一部分。

        $output .= "<{$itemtag} class='card'>";
    $output .= "<{$itemtag} class='card-block'>";
    $output .= "<{$itemtag} class='container-portfolio'>";
    $output .= '<img class="" src="' . wp_get_attachment_url( $id, 'medium', true) . '" />';

    I WANT TO INSERT THE CUSTOM LINK HERE

    $output .= "<{$itemtag} class='overlay'>";
    $output .= "<{$itemtag} class='card-body overlay-text'>";

0 个答案:

没有答案