xiuno教程:一个简单实现xiuno图片列表的小技巧 [复制链接]

moqu8 2018-7-6

2728 0
以下教程是直接在系统默认模板上进行实现的,新手在操作前请事先备份,或者在本地测试。
根据之前发布的获取文章中第一个图片教程
/thread-12997.htm
找到view/htm/thread_list.inc.htm页面

<?php if($threadlist) { foreach($threadlist as &$_thread) { ?>
<li class="media thread tap <?php echo $_thread['top_class'];?> " data-href="<?php echo url("thread-$_thread[tid]");?>" data-tid="<?php echo $_thread['tid'];?>">
<?php if($have_allowtop) { ?>
<?php if($_thread['allowtop']) { ?>
<input type="checkbox" name="modtid" class="mt-3 mr-2" value="<?php echo $_thread['tid']; ?>" />
<?php } ?
<?php } ?>
<a href="<?php echo url("user-$_thread[uid]");?>" tabindex="-1" class="ml-1 mt-1 mr-3">
<!--看这里,这里是会员头像-->
</a>
<!--{hook thread_list_inc_avatar_after.htm}-->
此处截图是列表当中会员头像的位置,我们可以在此处举例说明

根据获取文章中第一个图片的方法。


<?php
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
$content = $_thread['message']; //文章内容
preg_match_all($pattern,$content,$matchContent);
if(isset($matchContent[1][0])){
$temp = $matchContent[1][0];
}
?>
调用:


362655b3f0b992a3fb.png
此时可能会发现报错,原因是因为
$content = $_thread['message'];
文章内容部分,列表中获取不到这个字段。
那么我们简单写一个获取文章内容的一个小方法。
function ax_message($tid){
$r = db_find_one('post', array('tid'=>$tid));
return $r;
}
根据上面函数方法可以获取文章内容。那么我们将下列函数进行一下修改。

<?php
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
$content = ax_message($_thread['tid']); //文章内容
preg_match_all($pattern,$content,$matchContent);
if(isset($matchContent[1][0])){
$temp = $matchContent[1][0];
}
?>
然后在适当地方调用即可。



最新回复 (0)
返回
支持中心
邮箱:winkill2012@qqcom
新站优化中!部分功能尚未完善,敬请谅解!
支持中心