WordPress.org

Ready to get started?Download WordPress

Forums

automatically convert images from media gallery to post (2 posts)

  1. dashouguai
    Member
    Posted 2 years ago #

    Am running a blog, each post only includes exactly 1 picture from the media folder.

    Is there a way to automate this?

    I can batch upload my images to media folder, how can I batch create post using these images just uploaded?

    Thanks!!!!!

  2. zimmi88
    Member
    Posted 2 years ago #

    There's two ways you could go about this, I think...

    1. Create or use a theme that uses attachments as the primary post view. Attachments are considered posts within the database and have a place within the template hierarchy (details). If you want to go this route, take a look at WP_Query for more details on how to query posts.
    2. Hook in to the add_attachment action in WordPress. The documentation on this hook is a little sparse in the Codex, but check out this post on StackExchange for an example of how the hook can be used. In this case, when an image gets uploaded, you'll use the hook to call a function (probably placed in functions.php of your theme or as a plugin), which will pull up the attachment info and generate a new post from that (see wp_insert_post).

    You'll need to determine based upon your content whether using attachments as the primary post types (in a way) or creating a hook is the more appropriate solution. Both solutions will require some PHP coding (the hook solution is probably a little heavier on the PHP) - the former may also need some HTML/CSS work on the front end.

    I hope this helps!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags