In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how wordpress uses external chain pictures as thumbnails of the article. I hope you will gain a lot after reading this article. Let's discuss it together.
Train of thought:
1. Have a way to determine the address of the picture: the first picture in the article, or use the custom column to add a custom value.
2. Call the determined picture in the foreground: use the function method or call the picture directly.
The implementation is as follows:
Premise:
Any call is best made in a LOOP loop so that the $post value can be easily used.
1. Call the first picture in the article: use $post- > post_content to get the content of the article, and then use the matching method to get the SRC value of the first picture.
Preg_match ('/ / iFengjie Magnum postpost-> post_content,$index_piclink); if (count ($index_piclink) > = 2) $image_src = $index_piclink [1]; if (! strstr ($image_src,' http://'))$image_src = false)
2, call a custom column: when writing an article, add a custom column with the noun post_thumb, and then set it up with the address of the picture as the value. For example, meta_key:post_thumb,meta_value: http://www.utubon.com/images/logo.png, and then call it with the following methods:
$image_src = get_post_meta ($post- > ID,'post_thumb',true); $image_src = trim ($image_src)! ='? Trim ($image_src): false
3. Use them in the article loop
If ($image_src) echo'
'
4. Turn them into functions
Function get_thumb_src ($size = 'thumbnail',$first_pic_in_ctonte = true) {global $post;$image_src ='; if (function_exists ('has_post_thumbnail') & & has_post_thumbnail ()) {$image_id = get_post_thumbnail_id (); $image_src = wp_get_attachment_image_src ($image_id,$size); $image_src = $image_src [0];} else {$image_src = get_post_meta ($post- > ID,'post_thumb',$single=true) If (! $image_src & & $first_pic_in_ctonte) {preg_match ('/ / iFengjinzhuo > post_content,$index_piclink); if (count ($index_piclink) > = 2) $image_src = $index_piclink [1]; if (! strstr ($image_src,' http://'))$image_src = false;}} return $image_src;} function the_thumb_src ($size = 'thumbnail',$first_pic_in_ctonte = true) {echo get_thumb_src ($size,$first_pic_in_ctonte)) }
This function (put it in functions.php) realizes the selection of thumbnails of the article, if there is already a characteristic picture, then use a characteristic picture, if there is no post_thumb custom column, if not, use the first picture of the article, if there is no picture, return the false value. The use is as follows:
If (get_thumb_src ()) the_thumb_src (); after reading this article, I believe you have a certain understanding of wordpress's method of using outer chain pictures as article thumbnails. Want to know more about it. Welcome to follow the industry information channel. Thank you for your reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.