如何从媒体库中获取图像并按 Alt 标签排序

当你正在尝试从具有特定类别的媒体库中获取图像,然后按 alt 标签对它们进行排序(因为某些标题在标题的开头有一个星号,这会破坏按标题排序)。可以使用 显示图像本身中的替代文本get_post_meta(get_the_ID(), '_wp_attachment_image_alt', true) ,以下代码示例可以提供参考:

<?php $query_images_args = array
'post_type' => 'attachment'
'category_name' => 'colors',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => 30,
'meta_key' => '_wp_attachment_image_alt',
'orderby' => '_wp_attachment_image_alt',
'order' => 'ASC'
);
$query_images = new WP_Query( $query_images_args );
if($query_images->have_posts()) :
while($query_images->have_posts()) :
$query_images->the_post(); ?>

<h4><?php the_title(); ?></h4>
<?php echo $images = wp_get_attachment_image( $query_images->posts->ID, 'large', '', array( "class" => "img-fluid mx-auto d-block", "alt" => get_post_meta(get_the_ID() , '_wp_attachment_image_alt', true)));
?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
开发教程

如何从category.php页面上的 URL 回显一个或多个分类?

2022-10-21 11:49:37

开发教程

WordPress无法上传大图片

2022-11-16 12:08:18

12 条回复 A文章作者 M管理员
  1. Nice blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol

  2. Thank you, I have just been searching for information approximately this topic for a while and yours is the best I have found out so far. However, what in regards to the bottom line? Are you certain concerning the supply?

  3. you are in reality a good webmaster. The website loading velocity is amazing. It sort of feels that you’re doing any distinctive trick. Also, The contents are masterwork. you have done a fantastic job in this topic!

  4. I have been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  5. I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are wonderful! Thanks!

  6. hello!,I like your writing very so much! proportion we keep up a correspondence extra approximately your post on AOL? I need an expert in this space to unravel my problem. May be that is you! Taking a look forward to see you.

  7. Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how can we communicate?

  8. Usually I do not read article on blogs, however I would like to say that this write-up very compelled me to take a look at and do it! Your writing style has been amazed me. Thank you, very nice article.

  9. Simply desire to say your article is as surprising. The clearness in your post is simply excellent and i could assume you are an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with forthcoming post. Thanks a million and please carry on the gratifying work.

  10. I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the web will be much more useful than ever before.

  11. I was suggested this web site by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my trouble. You are incredible! Thanks!

  12. Wonderful web site. Lots of useful info here. I’m sending it to a few friends ans additionally sharing in delicious. And obviously, thanks to your effort!

个人中心
今日签到
有新私信 私信列表
搜索
赣ICP备2021010644号-1