Wordpress以自定义大小插入文章附件链接到自定义大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress以自定义大小插入文章附件链接到自定义大小相关的知识,希望对你有一定的参考价值。
To insert custom loop of post attachments as images (at core or custom size) linked not to full size image but custom-configured (or core) size.
<?php $postID = $post->ID; //print_r($product_meta); // (thumbnail, medium, large or full) or a 2-item array // representing width and height in pixels, e.g. array(32,32) // OR the custom config'd name of image size $image_size = 'prods-large'; // the image size to be shown initially (smaller version) $image_size_lg = 'large'; // the image size to link to (large version) 'post_parent' => $postID, 'post_type' => 'attachment', 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'menu_order', //'exclude' => get_post_thumbnail_id(), -- uncomment to exclude post thumbnail 'post_mime_type' => 'image', ) ); //print_r($images); if($images) { echo '<div class="prod-imgs">'; foreach( $images as $image ) { $attachment_id = $image->ID; // get the 'large' size image's URL $image_attributes = wp_get_attachment_image_src( $attachment_id, 'large' ); // returns an array - [0] is the URL of the image 'large' size $largeSizeURL = $image_attributes[0]; echo '<a class="attachment-' . $attachment_id . ' popup-with-zoom-anim img-link" href="' . $largeSizeURL . '">'; echo wp_get_attachment_image($attachment_id, $image_size); echo '</a>'; } echo '</div>'; } ?>
以上是关于Wordpress以自定义大小插入文章附件链接到自定义大小的主要内容,如果未能解决你的问题,请参考以下文章
使用 Wordpress,我如何创建一个链接到自定义帖子类型存档的新菜单项?
修改WordPress中上传附件2M大小限制的方法/php+iis上传附件默认大小修改方法