admin管理员组文章数量:1130349
Here's the deal: I was migrating the content (lots of posts) from an old site to a new one. The posts have multiple images attached to it (which I've noticed when I was importing the thumbnail images via WP All Import) and it is being nicely displayed in single.php template like this:
Main image
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_array->ID), 'full'); ?>
+ HTML markup
Little thumbnails beneath main image (if there are more than one images)
$images = sql_post_images( $ID = get_the_ID(), get_post_thumbnail_id( $ID ) );
foreach($images as $image) {
HTML markup
}
sql_post_images() function
function sql_post_images( $post_id, $exclude_id = 0 ) {
global $wpdb;
$data = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT wposts.ID,
wposts.post_title,
wposts.post_excerpt,
wposts.post_content,
wpostmeta.meta_value
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->postmeta wpostmeta
ON wpostmeta.post_id = wposts.ID
AND wpostmeta.meta_key = %s
WHERE wposts.post_parent = %d
AND wposts.post_type = 'attachment'
AND (wposts.post_mime_type = 'image/jpeg' OR wposts.post_mime_type = 'image/png' OR wposts.post_mime_type = 'image/gif')
AND wposts.ID != %d
ORDER BY wposts.menu_order ASC
", '_wp_attachment_metadata', $post_id, $exclude_id), ARRAY_A);
return( $data );
}
This works well and I would like to keep it like that in the future as well - the problem is I cannot find a solution to allow upload of multiple images to a post. I found some plugins, but their approach is clearly different (it's either just a second thumbnail image, or something similar). What could actually work?
EDIT: Uploading images as a classic WP attachments doesn't seem to do the trick.
Here's the deal: I was migrating the content (lots of posts) from an old site to a new one. The posts have multiple images attached to it (which I've noticed when I was importing the thumbnail images via WP All Import) and it is being nicely displayed in single.php template like this:
Main image
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_array->ID), 'full'); ?>
+ HTML markup
Little thumbnails beneath main image (if there are more than one images)
$images = sql_post_images( $ID = get_the_ID(), get_post_thumbnail_id( $ID ) );
foreach($images as $image) {
HTML markup
}
sql_post_images() function
function sql_post_images( $post_id, $exclude_id = 0 ) {
global $wpdb;
$data = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT wposts.ID,
wposts.post_title,
wposts.post_excerpt,
wposts.post_content,
wpostmeta.meta_value
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->postmeta wpostmeta
ON wpostmeta.post_id = wposts.ID
AND wpostmeta.meta_key = %s
WHERE wposts.post_parent = %d
AND wposts.post_type = 'attachment'
AND (wposts.post_mime_type = 'image/jpeg' OR wposts.post_mime_type = 'image/png' OR wposts.post_mime_type = 'image/gif')
AND wposts.ID != %d
ORDER BY wposts.menu_order ASC
", '_wp_attachment_metadata', $post_id, $exclude_id), ARRAY_A);
return( $data );
}
This works well and I would like to keep it like that in the future as well - the problem is I cannot find a solution to allow upload of multiple images to a post. I found some plugins, but their approach is clearly different (it's either just a second thumbnail image, or something similar). What could actually work?
EDIT: Uploading images as a classic WP attachments doesn't seem to do the trick.
Share Improve this question asked Oct 29, 2018 at 13:28 Kristián FiloKristián Filo 4316 silver badges20 bronze badges1 Answer
Reset to default 1Have you considered using the ACF plugin? ACF has a very convenient field type - gallery. I think it would match what you want a 100% without the need to poke around the native/custom DB queries. Check it out.
Here's the deal: I was migrating the content (lots of posts) from an old site to a new one. The posts have multiple images attached to it (which I've noticed when I was importing the thumbnail images via WP All Import) and it is being nicely displayed in single.php template like this:
Main image
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_array->ID), 'full'); ?>
+ HTML markup
Little thumbnails beneath main image (if there are more than one images)
$images = sql_post_images( $ID = get_the_ID(), get_post_thumbnail_id( $ID ) );
foreach($images as $image) {
HTML markup
}
sql_post_images() function
function sql_post_images( $post_id, $exclude_id = 0 ) {
global $wpdb;
$data = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT wposts.ID,
wposts.post_title,
wposts.post_excerpt,
wposts.post_content,
wpostmeta.meta_value
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->postmeta wpostmeta
ON wpostmeta.post_id = wposts.ID
AND wpostmeta.meta_key = %s
WHERE wposts.post_parent = %d
AND wposts.post_type = 'attachment'
AND (wposts.post_mime_type = 'image/jpeg' OR wposts.post_mime_type = 'image/png' OR wposts.post_mime_type = 'image/gif')
AND wposts.ID != %d
ORDER BY wposts.menu_order ASC
", '_wp_attachment_metadata', $post_id, $exclude_id), ARRAY_A);
return( $data );
}
This works well and I would like to keep it like that in the future as well - the problem is I cannot find a solution to allow upload of multiple images to a post. I found some plugins, but their approach is clearly different (it's either just a second thumbnail image, or something similar). What could actually work?
EDIT: Uploading images as a classic WP attachments doesn't seem to do the trick.
Here's the deal: I was migrating the content (lots of posts) from an old site to a new one. The posts have multiple images attached to it (which I've noticed when I was importing the thumbnail images via WP All Import) and it is being nicely displayed in single.php template like this:
Main image
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_array->ID), 'full'); ?>
+ HTML markup
Little thumbnails beneath main image (if there are more than one images)
$images = sql_post_images( $ID = get_the_ID(), get_post_thumbnail_id( $ID ) );
foreach($images as $image) {
HTML markup
}
sql_post_images() function
function sql_post_images( $post_id, $exclude_id = 0 ) {
global $wpdb;
$data = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT wposts.ID,
wposts.post_title,
wposts.post_excerpt,
wposts.post_content,
wpostmeta.meta_value
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->postmeta wpostmeta
ON wpostmeta.post_id = wposts.ID
AND wpostmeta.meta_key = %s
WHERE wposts.post_parent = %d
AND wposts.post_type = 'attachment'
AND (wposts.post_mime_type = 'image/jpeg' OR wposts.post_mime_type = 'image/png' OR wposts.post_mime_type = 'image/gif')
AND wposts.ID != %d
ORDER BY wposts.menu_order ASC
", '_wp_attachment_metadata', $post_id, $exclude_id), ARRAY_A);
return( $data );
}
This works well and I would like to keep it like that in the future as well - the problem is I cannot find a solution to allow upload of multiple images to a post. I found some plugins, but their approach is clearly different (it's either just a second thumbnail image, or something similar). What could actually work?
EDIT: Uploading images as a classic WP attachments doesn't seem to do the trick.
Share Improve this question asked Oct 29, 2018 at 13:28 Kristián FiloKristián Filo 4316 silver badges20 bronze badges1 Answer
Reset to default 1Have you considered using the ACF plugin? ACF has a very convenient field type - gallery. I think it would match what you want a 100% without the need to poke around the native/custom DB queries. Check it out.
本文标签: customizationHow to allow multiple thumbnail upload for Posts
版权声明:本文标题:customization - How to allow multiple thumbnail upload for Posts? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749224257a2335424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论