WordPress: Function Reference/wp insert attachment:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: ==Description== This function inserts an attachment into the media library. The function should be used in conjunction with [[WordPress:Function_Reference/wp_update_attachment_metadata|wp...)
 
无编辑摘要
 
(未显示另一用户的1个中间版本)
第1行: 第1行:
==Description==
==描述==
This function inserts an attachment into the media library. The function should be used in conjunction with [[WordPress:Function_Reference/wp_update_attachment_metadata|wp_update_attachment_metadata()]] and [[WordPress:Function_Reference/wp_generate_attachment_metadata|wp_generate_attachment_metadata()]]. Returns the ID of the entry created in the wp_posts table.
这个函数向媒体库添加了配属。函数应该与[[WordPress:Function_Reference/wp_update_attachment_metadata|wp_update_attachment_metadata()]] [[WordPress:Function_Reference/wp_generate_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插入一个配属:
 
<pre>
<pre>
<?php
<?php
第15行: 第18行:
</pre>
</pre>


==Parameters==
==参数==
{{Parameter|$attachment|array|Array of data about the attachment that will be written into the wp_posts table of the database. Must contain at a minimum the keys post_title, post_content (the value for this key should be the empty string) and post_status.}}
{{Parameter|$attachment|array|关于写进数据库中wp_post表格中的配属的数据数组,必须包含在一个最小的关键字post_title, post_content (这个关键字的参数值应该是空字符串) 和post_status.}}
{{Parameter|$filename|string|Location of the file on the server. Use absolute path and not the URI of the file.|optional|false}}
{{Parameter|$filename|string|文件在服务器上的位置。使用绝对路径而不是文件的URI。 |optional|false}}
{{Parameter|$parent_post_id|int|Attachments are associated with parent posts. This is the ID of the parent's post ID.|optional|0}}
{{Parameter|$parent_post_id|int|附属与parent文章相关联。这是parent文章的ID。|optional|0}}


==Related==
==相关的==
[[WordPress:Function Reference/wp get attachment url|wp_get_attachment_url()]], [[WordPress:Function Reference/wp delete attachment|wp_delete_attachment()]], [[WordPress:Function Reference/wp insert post|wp_insert_post()]]
[[WordPress:Function Reference/wp get attachment url|wp_get_attachment_url()]], [[WordPress:Function Reference/wp delete attachment|wp_delete_attachment()]], [[WordPress:Function Reference/wp insert post|wp_insert_post()]]

2008年7月24日 (四) 15:52的最新版本

描述[ ]

这个函数向媒体库添加了配属。函数应该与wp_update_attachment_metadata()wp_generate_attachment_metadata()一起使用。返回wp_posts表格中创建的文章的ID。

用法[ ]

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

例子[ ]

向文章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 );
?>

参数[ ]

相关的[ ]

wp_get_attachment_url(), wp_delete_attachment(), wp_insert_post()