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行: | ||
== | ==描述== | ||
这个函数向媒体库添加了配属。函数应该与[[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。 | |||
==用法== | |||
%%% <?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?> %%% | %%% <?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?> %%% | ||
== | ==例子== | ||
向文章ID为37的parent插入一个配属: | |||
<pre> | <pre> | ||
<?php | <?php | ||
第15行: | 第18行: | ||
</pre> | </pre> | ||
== | ==参数== | ||
{{Parameter|$attachment|array| | {{Parameter|$attachment|array|关于写进数据库中wp_post表格中的配属的数据数组,必须包含在一个最小的关键字post_title, post_content (这个关键字的参数值应该是空字符串) 和post_status.}} | ||
{{Parameter|$filename|string| | {{Parameter|$filename|string|文件在服务器上的位置。使用绝对路径而不是文件的URI。 |optional|false}} | ||
{{Parameter|$parent_post_id|int| | {{Parameter|$parent_post_id|int|附属与parent文章相关联。这是parent文章的ID。|optional|0}} | ||
== | ==相关的== | ||
[[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()