If there are greater than or equal to 4 photos, name 4 photos. If there are lower than 4 photos, name the primary picture or characteristic picture as thumbnail. If there is no such thing as a thumbnail, it’s best to not show it. To assist exterior linked footage.
like this. The archive checklist outputs a number of photos from the article it belongs to:
title
Picture 1. Picture 2, Picture 3, Picture 4
title
first picture (or featured picture)
…………
loop output
I’ve discovered a number of codes that solely meet a few of the wants. Learn how to mix these features, or there’s a higher means (perform code)
perform hui_get_thumbnail( $single=true, $should=true ) {
world $publish;
$html="";
if ( has_post_thumbnail() ) {
$domsxe = simplexml_load_string(get_the_post_thumbnail());
$src = $domsxe->attributes()->src;
$src_array = wp_get_attachment_image_src(hui_get_attachment_id_from_src($src), 'thumbnail');
$html = sprintf('<li><img src="%s" /></li>', $src_array[0]);
} else {
$content material = $post->post_content;
preg_match_all('/<img.*?(?: |t|r|n)?src=['"]?(.+?)['"]?(?:(?: |t|r|n)+.*?)?>/sim', $content material, $strResult, PREG_PATTERN_ORDER);
$photos = $strResult[2];
$counter = depend($strResult[2]);
$i = 0;
foreach($photos as $src){
$i++;
$src2 = wp_get_attachment_image_src(hui_get_attachment_id_from_src($src), 'thumbnail');
$src2 = $src2[0];
if( !$src2 && true ){
$src = $src;
}else{
$src = $src2;
}
$merchandise = sprintf('<li><img src="%s" /></li>', $src);
if( $single){
return $merchandise;
break;
}
$html .= $merchandise;
if(
($counter >= 4 && $counter < 8 && $i >= 4) ||
($counter >= 8 && $i >= 8) ||
($counter > 0 && $counter < 4 && $i >= $counter)
){
break;
}
}
}
return $html;
}
perform hui_get_attachment_id_from_src ($hyperlink) {
world $wpdb;
$hyperlink = preg_replace('/-d+xd+(?=.(jpg|jpeg|png|gif)$)/i', '', $hyperlink);
return $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE guid='$hyperlink'");
}
perform all_img($soContent){
$soImages="~<img [^>]* />~";
preg_match_all( $soImages, $soContent, $thePics );
$allPics = depend($thePics);
if( $allPics > 0 ){
foreach($thePics[0] as $v){
echo $v;
}
}
else {
echo "<img src="https://wordpress.stackexchange.com/questions/407573/";
echo bloginfo("template_url');
echo "/photos/thumb.gif'>";
}
}
register_nav_menus( array(
'major' => __( 'Major Navigation'),
));
perform catch_that_image() {
world $publish, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+?src=['"]([^'"]+)['"].*?>/i', $post->post_content, $matches);
$first_img = $matches[2][0];
return $first_img;
}