公告:

wordpress获取分类缩略图

作者:star0312 / 时间:12年前 (2013/07/11) / 分类:未命名 / 阅读:2162 / 评论:0
今有用朋友问我的WordPress主题首页是怎样实现指定内容缩略图显示的,我想既然朋友问了,那就一定要帮忙了所以准备把具体的代码及用法公布一下,其实也就是利用WordPress自定义域实现的,希望对大家有帮助啊!
完整代码如下:

<?php query_posts(“showposts=5&cat=7″ ); ?>
<?php while (have_posts()) : the_post(); ?>
<h2><a href=<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2><div class=”meta”>[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div><a href=<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>>
<img src=<?php $key=”image” ; echo get_post_meta($post->ID, $key, true); ?>
alt=<?php the_title(); ?>” width=109px” height=100px”  />
</a>
             <?php the_excerpt(); ?>
             <a href=<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>>Read the full story ?</a>

<?php endwhile; ?>


代码分解:

<?php query_posts(“showposts=5&cat=7″ ); ?>


这段代码的意思就是调用的分类id为 7 ,并且只显示 5 篇日志。

<h2><a href=<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

<div class=”meta”>[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div>

这段代码的作用是调用日志标题及想信息

<a href=<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>>
<img src=<?php $key=”image” ; echo get_post_meta($post->ID, $key, true); ?>
alt=<?php the_title(); ?>” width=109px” height=100px”  />
</a>


这段代码的作用是调用日志的图片,不过需要在撰写日志的时候新建一个image自定义域啊。 其中width=”100px代表图片的宽度 height=”100px”代表图片的高度。

<?php the_excerpt(); ?>

<a href=<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>>Read the full story ?</a>
 
 
 
 
我的一个实例:
 
<ul class="project-carousel">
          <?php query_posts('showposts=8&cat=3'); ?>
          <?php while(have_posts()):the_post(); ?>
          <li>
          <div class="project-item">
          <img src="<?php echo get_post_meta(get_the_ID(),'image',true)?>" height="222" width="222"/>
          <div class="overlay">
          <a href="<?php $key=”image”; echo get_post_meta($post->ID, $key, true); ?>" class="lightbox-link folio" rel="gallery"></a>
          <a href="<?php the_permalink() ?>"><h5><?php the_title(); ?></h5></a>
          </div>
          </div>
      </li>
          <?php // the_excerpt(); ?><!--显示文章摘要-->
          <?php endwhile; ?>
    </ul>
 
  • 我的QQ二维码
  • QQ群
  • 我的微信二维码
  • 微信公众号

没有评论,留下你的印记,证明你来过。


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。