I want to get Thumbnail and full size images from custume post type.
Can anyone help me with how I can get the the title of image and thumbnail id in wordpress?
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title', $attachment->post_title );
the_attachment_link( $attachment->ID, false );
}
}
?>
Try this hope it's help for you
Related
For a special gallery i need to show all woocommerce variation images. On the woocommerce content-single-product.php i can access the variations but i cant get the image url out of it. How can i do that?
Inside my content-single-product.php overwrite:
<?php
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => $post->ID
);
$variations = get_posts( $args );
echo "<pre>"; print_r($variations); echo "</pre>";
?>
You can do something like this.
$product = new WC_Product_Variable( $product_id );
// get the product variations
$product_variations = $product->get_available_variations();
if ( !empty( $product_variations ) ) {
foreach($product_variations as $product_variation) {
echo $product_variation['image_src'];
}
}
I'm new to WordPress programming
I created a WordPress postal warehouse called "wp_locations"
I need to show the title of this post on the page
I put the following code in the my theme index file
<?php $gallery_args = array(
'posts_per_page' => -1,
'orderby'=> 'date',
'order'=> 'DESC',
'post_type'=> 'wp_locations',
'post_status'=> 'publish',
'suppress_filters' => true
);
$posts_display_gallery = get_posts( $gallery_args );
foreach($posts_display_gallery as $rows){
$post_title = $rows->post_title;
} ?>
But did not display the title
please guide me
Please use echo in your code
echo $post_title = $rows->post_title;
Please try below code and check it again....
<?php
global $post;
$gallery_args = array(
'posts_per_page' => -1,
'orderby'=> 'date',
'order'=> 'DESC',
'post_type'=> 'wp_locations',
'post_status'=> 'publish',
'suppress_filters' => true
);
$posts_display_gallery = get_posts( $gallery_args );
foreach ( $posts_display_gallery as $post ) : setup_postdata( $post );
$post_title = $post->post_title; // Like this you will get post title.
echo $post_title; // For display
endforeach;
wp_reset_postdata();?>
Hope this will helpful for you.
<?php $gallery_args = array(
'posts_per_page' => -1,
'orderby'=> 'date',
'order'=> 'DESC',
'post_type'=> 'wp_locations',
'post_status'=> 'publish',
'suppress_filters' => true
);
$posts_display_gallery = get_posts( $gallery_args );
foreach($posts_display_gallery as $rows){
$post_title = $rows->post_title;
echo $post_title; // for display the title
} ?>
You may try with this piece of code, should work
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ){
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$product_id = $loop->post->ID;
$product_title = $loop->post->post_title;
endwhile;
}
Try get_the_title() in the foreach loop
I trying to use wp_playlist_shortcode for creating playlist with audio-files from all blog posts.
In official documentation i saw this parameter:
'ids'
(array) Create a playlist out of these explicit attachment IDs. If empty, a playlist will be created from all $type attachments of $id. Default empty.
I trying this code, and its doesn't working:
$attch_id = array('76', '73', '70', '67');
wp_playlist_shortcode( array( 'ids' => '$attch_id' );
How to create playlist with audio-files from all blog posts? Now i use this code, but it is a not playlist.
$audios = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => null, 'post_mime_type' => 'audio/mpeg' );
$attachments = get_posts( $audios );
if ($attachments) {
foreach ( $attachments as $post ) {
setup_postdata($post);
$media_url = $post->guid;
$media_title = $post->post_title;
echo wp_audio_shortcode( array( 'src' => $media_url) );
echo '<p>' . $media_title . '</p>';
// print_r($media_url);
}
}
wp_reset_postdata();
I made an Wordpress theme, with pages and posts.
The loop of posts show me a short brief of post and a Continue reading link.
I like this, but how can I make the theme show in the post brief of the loop image(s) attached to post at beginning, if any.
Thank you!
You can get your attached images by using:
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_parent' => $post->ID
);
$images = get_posts($args);
and display it like this:
echo wp_get_attachment_image($images[0]->ID, $size='attached-image');
This for getting all attachement images with your post.
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
$img = wp_get_attachment_image_src($post->ID, 'medium');
$fullsize = wp_get_attachment_image_src($post->ID, 'full');
}
}
You should add in your loop:
<?php
if(has_post_thumbnail()) {
$theimage = wp_get_attachment_image_src( get_post_thumbnail_id ( $post->ID ), 'thumbnail' );
}
?>
<img class="img_class" src="<?php echo $theimage[0]; ?>" />
Where "thumbnail" correspond to the size you want to show.
Remember that there is also a WordPress specific site in StackExchange
How i can show attached images of my posts on Wordpress?
Try this in your single.php template:
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $post->ID
);
$images = get_posts( $args );
foreach($images as $image):
echo wp_get_attachment_image($image->ID, 'medium');
endforeach;
wp_get_attachment_image