简体   繁体   English

Wordpress如何通过图像名称将图像自动添加到自定义帖子?

[英]Wordpress How to to add images automatically to a custom post by image name?

I have a folder that i created that are filled using ftp. 我有一个使用ftp填充的文件夹。

To be enable to allocate witch photo should go to what post the photos are named with a unique custom field that the post is using. 要启用分配女巫照片的功能,请转到该照片使用了该帖子使用的唯一自定义字段命名的帖子。

For example Custom post type = car >> each post in car have car license number (custom field), for example= 311111 >> wp-upload contains folder named car-photos >> the photo that feet this car post is named 311111-photo-01.jpg. 例如,自定义帖子类型=汽车>>汽车中的每个帖子都有汽车牌照编号(自定义字段),例如= 311111 >> wp-upload包含名为car-photos的文件夹>>该汽车帖子脚上名为311111-的照片照片01.JPG。

What I am trying to do is to create a php file that will work on cron job. 我正在尝试做的是创建一个将在cron作业中工作的php文件。 The php file work is to get all the images in the specific folder,look for the same unique identifier as the post have (in a custom field) and create to this post a gallery from all the this photos. php文件的工作是获取特定文件夹中的所有图像,查找与帖子具有相同的唯一标识符(在自定义字段中),并从所有这些照片中创建一个图库。

This is hard for me to explain but hopefully you get me.. Any ideas ? 这对我来说很难解释,但希望您能理解我。有什么想法吗?

What you are asking is a whole plugin , not just a few lines of code - therefor i will describe the theory and important functions. 您要问的是一个完整的插件,而不仅仅是几行代码-为此,我将介绍其理论和重要功能。 I have myself made a custom plugin for internal use that does a very similar thing . 我自己做了一个供内部使用的自定义插件,其功能非常相似。

Basically you need to scan your car-photos folder, then for each image found sanitize the name and then use media_sideload_image function ( or see equivalents below ) according to a query object match of posts by custom fields. 基本上,您需要扫描car-photos文件夹,然后为找到的每个图像清理名称,然后根据自定义字段对帖子的查询对象匹配,使用media_sideload_image函数(或参见下面的等效项)。

The media_sideload_image or wp_handle_sideload and others like media_handle_upload() , media_handle_sideload() , wp_handle_upload() , wp_import_handle_upload() , wp_handle_sideload() , media_sideload_image() are the crutial part for this task - all are searchable in codex . media_sideload_imagewp_handle_sideload以及其他诸如media_handle_upload()media_handle_sideload()wp_handle_upload()wp_import_handle_upload()wp_handle_sideload()media_sideload_image()是此任务的关键部分-所有这些都可以在代码中搜索。

About cron - I myself have not implemented it using cron but with 2 different methods : 1 ) an execution on demand button and 2) a hook on some initial function that will execute every time the site is accessed ( or a specific url / page / theme file ). 关于cron-我本人并没有使用cron来实现它,而是使用了2种不同的方法:1)按需执行按钮2)钩住了一些初始功能,每次访问该网站(或特定的url / page /主题文件)。 user can choose between the two methods . 用户可以在两种方法之间进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建帖子时如何自动将特色图片添加到自定义帖子? - How to automatically add a featured image to a custom post when the post is created? 如何将多个图像添加到Wordpress中的自定义帖子中以查看作品集详细信息页面 - How to add multiple images into custom post in wordpress for portfolio detail page 如何让wordpress自动添加精选图片? - How to let wordpress automatically add a featured image? wordpress上如何在多张精选图片中自动添加图片 - How to automatically add images in multiple Featured Images on wordpress 如何在每个WordPress帖子图像周围添加div并检索悬停的图像以进行社交共享? - How do I add div around each WordPress post images & retrieve hovered image for social sharing? 如何在Wordpress的自定义元框中添加帖子类别 - How to add Post Category In Custom Metaboxes of wordpress 如何在WordPress的帖子中添加自定义标签框? - How to add custom tags box in wordpress post? 如何在wordpress post slug中添加自定义术语? - How to add custom term in wordpress post slug? WordPress如何使用自定义名称输出下一篇和上一篇文章? - WordPress How to output next post and previous post with custom name? 自定义Wordpress用户角色无法将图片添加到帖子中 - Custom Wordpress User role can't add image into post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM