ใครเก่ง PHP,Wordpressช่วยแนะนำหน่อยครับไม่รู้ว่าผมพลาดตรงไหนไป มือใหม่ครับ

เริ่มโดย adjobb, 12 ธันวาคม 2015, 18:24:58

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

adjobb

พอภาพทำ timthumb ย่อภาพเสร็จหมดแล้วแต่มาติดตรงนี้ครับ ถ้าให้อธิบายไม่เข้าใจแน่ๆเลย งั้นอธิบายเป็นภาพดีกว่า  :-[



สามารถแก้ยังไงไม่ให้ภาพสีเทาแสดงตอนเรามีภาพได้ครับ


<a href="<?php the_permalink() ?>" class="uk-thumbnail post-image" title="<?php the_title() ?>">
<?php if (postimage(768,384)): ?>
<?php postimage('jindaCover', array('alt' => get_the_title())) ?>
<?php else: ?>
<img src="http://www.placehold.it/768x384" alt="<?php the_title() ?>" />
<?php endif ?>
</a>

TonHaDy

มือใหม่เหมือนกัน ลองดูตัวนี้ครับ

https://codex.wordpress.org/Function_Reference/has_post_thumbnail
[direct=https://www.facebook.com/HadyShop/]hadyshop[/direct]
[direct=http://www.hadyshop.com]เสื้อผ้าแฟชั่น, เสื้อผ้าแฟชั่นเกาหลี ทั้งพร้อมส่ง และพรีออเดอร์[/direct]
[direct=http://www.roojaishop.com/]เสื้อผ้าแฟชั่นพร้อมส่ง สไตล์เกาหลี ราคาถูก[/direct]

witme

ไม่ใั่นใจแต่ขอเดานะครับ

<img src="http://www.placehold.it/768x384" alt="......>

ตรง src น่าจะต้องเป็นชื่อไฟล์ ที่มีการใส่นามสกุลอย่างถูกต้องนะครับ เช่น jpg

9keepgoing

<a href="<?php the_permalink() ?>" class="uk-thumbnail post-image" title="<?php the_title() ?>">
<?php if (postimage(768,384)){ ?>
<?php postimage('jindaCover', array('alt' => get_the_title())) ?>
<?php }else{ ?>
<img src="http://www.placehold.it/768x384.png" alt="<?php the_title() ?>" />
<?php } ?>
</a>

DEVELOPER & CONSULTANT(ONLINE MARKETING)

romance69

ลองดูตัวนี้ว่าได้ไหม

<a href="<?php the_permalink() ?>" class="uk-thumbnail post-image" title="<?php the_title() ?>">
<?php if ('' != get_the_post_thumbnail()): ?>
<?php the_post_thumbnail(); ?>
<?php else: ?>
<img src="http://www.placehold.it/768x384.png" alt="<?php the_title() ?>" />
<?php endif ?>
</a>
ขายปลั๊กอิน Wordpress ตรวจหวยออนไลน์ อัปเดตอัตโนมัติ ราคา 2,500 บาท ใส่โค้ด THAISEO10 รับส่วนลด 10%
รับเขียนเว็บไซต์, รับเขียน Theme wordpress, รับเขียน Plugin wordpress

adjobb

โอ้ขอบคุณทั้ง 4 ท่านมากเลยครับ TonHaDy, witme, 9keepgoing, romance69 +1

ผมใช้อีกวิธีลบให้สั้นจิ๋วกว่าเดิมโดยการเรียกใช้แต่ <?php postimage(768,384) ?> ลืมไปเลยว่าใน functions ที่ผมโหลดมาโมนั้นมันมีภาพ default มาให้อยู่แล้ว  :wanwan012: ผมนี้นำโค้ดมาแปะจนลืมตรวจทานเลยว่า functions มันมีมาอยู่แล้ว

อันนี้จากโค้ดเดิม

<a href="<?php the_permalink() ?>" class="uk-thumbnail post-image" title="<?php the_title() ?>">
<?php if (postimage(768,384)): ?>
<?php postimage('jindaCover', array('alt' => get_the_title())) ?>
<?php else: ?>
<img src="http://www.placehold.it/768x384" alt="<?php the_title() ?>" />
<?php endif ?>
</a>


สรุปใช้แค่นี้ครับโดยลบโค้ดเก่าออก

<a href="<?php the_permalink() ?>" class="uk-thumbnail post-image" title="<?php the_title() ?>">
<?php postimage(768,384?>
</a>



function postimage($width,$height) {
    $scriptpath = get_bloginfo('template_directory');
    $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
$img = array_shift($attachments);
$imagelink = wp_get_attachment_image_src($img->ID,'full');
$image = $imagelink[0];

if($image=='') {
    $image = $scriptpath."/img/default.gif";
echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />';
}else {
        echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />';

}
}