Hi ananzhe25
It’s not really clear what it is you want to do.
Remove the filter from your functions.php file and add the thumbnails in theme template files directly?
https://developer.wordpress.org/themes/basics/template-files/
Or something else?
on workaround it would work like this in functions.php of your your theme:
add_filter( ‘the_content’, ‘put_thumbnail_in_posting’ );
function put_thumbnail_in_posting( $content )
{
if ( ‘advert’ == get_post_type() )
{
$args = array(
‘order’ => ‘ASC’,
‘post_mime_type’ => ‘image’,
‘post_parent’ => get_the_ID(),
‘post_status’ => null,
‘post_type’ => ‘attachment’,
);
$attachments = get_children( $args );
if ( $attachments ) {
$thumbnails = ”;
foreach( $attachments as $attachment )
{
$thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
‘style’ => ‘float:left;margin:15px;display:none;’
style => ng-controller-list ) );
}
$content = $thumbnails . $content;
}
}
return $content;
}lie this, you will be able to use angular js
simple example
Thank you for all the replies,
I am trying to move the code from function.php to single-post.php and get the same results.. I hope this is more clear.
Remove the filter and function from your theme’s functions.php file
And put this in your single-post.php (or single-advert.php) file.
<?php
$args = array(
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => get_the_ID(),
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
if ( $attachments ) {
$thumbnails = '';
foreach ( $attachments as $attachment ) {
$thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
'style' => 'float:left;margin:15px;'
) );
}
echo $thumbnails;
}
?>
https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
keesiemeijer Thank you so much! I appreciate it.
How to seclude this result for custom post ‘advert’ only?
The single-post.php file is only used for single posts.
Where do you want to exclude (or include) custom post type advert posts?
The default is single-advert.php but I need to use the code in a third party plugins where the code need to load the attached images if any attached to the custom post ‘advert’
The custom posts ‘advert’ is already included in my latest posts. What I need is the code to look for advert posts only and return any attached images.
I think that what the if ( 'advert' == get_post_type() ) meant to do
Here what my testing gave me
<?php
if ( 'advert' == get_post_type() )
{
$args = array(
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => get_the_ID(),
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
if ( $attachments ) {
$thumbnails = '';
foreach( $attachments as $attachment )
{
$thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
'style' => 'float:left;margin:1px;'
) );
}
}
}
echo $thumbnails;
?>
It seems working
Ha. You solved it yourself!
Very good π