WordPress:Function Reference/wp insert attachment

来自站长百科
Fludlen讨论 | 贡献2008年7月19日 (六) 14:37的版本
跳转至: 导航、​ 搜索

Description

描述

This function inserts an attachment into the media library. The function should be used in conjunction with wp_update_attachment_metadata() and wp_generate_attachment_metadata(). Returns the ID of the entry created in the wp_posts table. 这个函数向媒体库添加了配属。函数应该与wp_update_attachment_metadata()wp_generate_attachment_metadata()一起使用。返回wp_posts表格中创建的文章的ID。

Usage

用法

%%% <?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?> %%%

%%% <?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?> %%%

Example

例子

To insert an attachment to a parent with a post ID of 37:

向文章ID为37的parent插入一个配属:

<?php
  $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
  wp_update_attachment_metadata( $attach_id,  $attach_data );
?>
<?php
  $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
  wp_update_attachment_metadata( $attach_id,  $attach_data );
?>

Parameters

参数

Related

相关的

wp_get_attachment_url(), wp_delete_attachment(), wp_insert_post()