رفتن به مطلب

شخصی سازی گالری وردپرس


پست های پیشنهاد شده

چطوریشو شما باید بفرمایید - شما اسلایدر ساختید و می دونید چی ساختید

گالری در یک پست تولید میشه و در هر پست ممکنه یک یا چند گالری وجود داشته باشه

حالا اسلایدر شما در کجا قراره نمایش داده بشه و قراره کدوم یکی از گالری ها رو اسلاید کنه؟

لینک به ارسال

این دو کد رو بررسی کنید:

<?php

$attachments = get_children(array('post_parent' => $post->ID,

'post_status' => 'inherit',

'post_type' => 'attachment',

'post_mime_type' => 'image',

'order' => 'ASC',

'orderby' => 'menu_order ID'));

foreach($attachments as $att_id => $attachment) {

$full_img_url = wp_get_attachment_url($attachment->ID);

$split_pos = strpos($full_img_url, 'wp-content');

$split_len = (strlen($full_img_url) - $split_pos);

$abs_img_url = substr($full_img_url, $split_pos, $split_len);

$full_info = @getimagesize(ABSPATH.$abs_img_url);

?>

<div class="WallSizesHolder">

<div class="WallSizesThumbHolder">

<a href="<?php echo $full_img_url; ?>" title="<?php echo $attachment->post_title; ?>" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/thumb.php?src=<?php echo $full_img_url; ?>&w=92&h=69&zc=1" /></a>

</div>

<p><?php echo $full_info[0].'x'.$full_info[1]; ?></p>

</div>

<?php

}

?>

و

WPBeginner» Blog» Themes» How to Get All Post Attachmen…

How to Get All Post Attachments in WordPress Except for Featured Image

Last updated on February 6th, 2012 by Editorial Staff

Share & Comment

70

10

8

13

BlueHost - Recommended WordPress Hosting

How to Get All Post Attachments in WordPress Except for Featured Image

Recently while working on a custom project for a client, we had to get all post attachments from a custom post type and display them at one place. Because we were creating a grid display, we had each post’s featured image serving the purpose of a separator. This is why when getting all post attachments, we needed to exclude the featured image, so it doesn’t show up twice. In this article, we will show you how to get all post attachments in WordPress except for the featured image.

All you have to do is paste the following code inside a loop.

<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {

$attachments = get_posts( array(

'post_type' => 'attachment',

'posts_per_page' => -1,

'post_parent' => $post->ID,

'exclude' => get_post_thumbnail_id()

) );

if ( $attachments ) {

foreach ( $attachments as $attachment ) {

$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );

$thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );

echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';

}

}

}

?>

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...