dongmeng2687 2011-09-07 18:56 采纳率: 0%
浏览 70
已采纳

如何从wordpress post获取第一张图片调整大小(50x50缩略图)然后显示它?

I got this code which address my "Get the 1st image of the post then display it" issue.

<?php echo get_first_image() ?>

My problem is, how to i make it to automatically adjust its size (lets say 50x50) then display it.

What i want to to do is simply get the image from my published post, resize it (50x50 and 250x250) then display it. It will be use in a slider/enhance version of recent post.

thank you very much!

HERES THE CODE of the SLIDER/Recent post

$(".main_image .desc").show(); 
$(".main_image .block").animate({ opacity: 0.85 }, 1 ); 
$(".image_thumb ul li:first").addClass('active'); 
$(".image_thumb ul li").click(function(){
    //Set Variables
    var imgAlt = $(this).find('img').attr("alt");
    var imgTitle = $(this).find('a').attr("href"); 
    var imgDesc = $(this).find('.block').html();  
    var imgDescHeight = $(".main_image").find('.block').height(); 
    if ($(this).is(".active")) {  
        return false; 
    } else { 
        //Animate the Description
        $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { 
            $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); 
            $(".main_image img").attr({ src: imgTitle , alt: imgAlt});
        });
    }
    //Show active list-item
    $(".image_thumb ul li").removeClass('active');
    $(this).addClass('active');
    return false; 
}) .hover(function(){ 
    $(this).addClass('hover'); 
    }, function() {
    $(this).removeClass('hover');
});
$("a.collapse").click(function(){
    $(".main_banner .block").slideToggle();
    $("a.collapse").toggleClass("show"); 
});
<div class="main_image">
    <img src="banner1.jpg" alt="" />
    <div class="desc">
        <a href="#" class="collapse">Close Me!</a>
        <div class="block">
            <h2>Title</h2>
            <small>Date</small>
            <p>Copy</p>
        </div>
    </div>
</div>
<div class="image_thumb">
<ul>
<li>
<a href="banner1.jpg"><img src="image\banner1_thumb.jpg" alt="image1234" /></a>
<div class="block">
<h2>Title</h2>
<small>Date</small>
<p>Copy</p>
</div>
</li>
</ul>
</div>
.main_image {
    width: 598px;
    height: 456px;
    float: left;
    background: #333;
    position: relative;
    overflow: hidden; 
    color: #fff;
}
.main_image h2 {
    font-size: 2em;
    font-weight: normal;
    margin: 0 0 5px;
    padding: 10px;
}
.main_image p {
    font-size: 1.2em;
    line-height: 1.6em;
    padding: 10px;
    margin: 0;
}
.block small { 
    font-size: 1em;
    padding: 0 0 0 20px;
    background: url(iconcalendarKO.gif) no-repeat 0 center;
}
.main_image .block small {margin-left: 10px;}
.main_image .desc{
    position: absolute;
    bottom: 0;
    left: 0; 
    width: 100%;
    display: none; 
.main_image .block{
    width: 100%;
    background: #111;
    border-top: 1px solid #000;
}
.main_image a.collapse { 
    background: url(btn_collapse.gif) no-repeat left top;
    height: 27px;
    width: 93px;
    text-indent: -99999px;
    position: absolute;
    top: -27px;
    right: 20px;
}
.main_image a.show {background-position: left bottom;}image_thumb section CSS
.image_thumb {
    float: left;
    width: 299px;
    background: #f0f0f0;
    border-right: 1px solid #fff;
    border-top: 1px solid #ccc;
}
.image_thumb img {
    border: 1px solid #ccc;
    padding: 5px;
    background: #fff;
    float: left;
}
.image_thumb ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.image_thumb ul li{
    margin: 0;
    padding: 12px 10px;
    background: #f0f0f0 url(nav_a.gif) repeat-x;
    width: 279px;
    float: left;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #fff;
    border-right: 1px solid #ccc;
}
.image_thumb ul li.hover { 
.image_thumb {
    float: left;
    width: 299px;
    background: #f0f0f0;
    border-right: 1px solid #fff;
    border-top: 1px solid #ccc;
}
.image_thumb img {
    border: 1px solid #ccc;
    padding: 5px;
    background: #fff;
    float: left;
}
.image_thumb ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.image_thumb ul li{
    margin: 0;
    padding: 12px 10px;
    background: #f0f0f0 url(nav123_a.gif) repeat-x;
    width: 279px;
    float: left;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #fff;
    border-right: 1px solid #ccc;
}
.image_thumb ul li.hover { 
    background: #ddd;
    cursor: pointer;
}
.image_thumb ul li.active { 
    background: #fff;
    cursor: default;
}
html .image_thumb ul li h2 {
    font-size: 1.5em;
    margin: 5px 0;
    padding: 0;
}
.image_thumb ul li .block {
    float: left;
    margin-left: 10px;
    padding: 0;
    width: 170px;
}
.image_thumb ul li p{display: none;}
  • 写回答

1条回答 默认 最新

  • dp13668681869 2011-09-07 21:23
    关注

    isnt get_the_post_thumbnail enough? Just call it twice, with different sizes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助