公用列表

燃烧的冰2020-01-11  6.4K+

wellcms 模板中很多地方加载了公用列表文件,尤其是扁平模式下,首页、频道、列表、搜索页、用户中心、我的首页等很多地方都加载了这个文件,引用加载无需重复写代码,一个文件多处引用。

 

对应文件 view/htm/thread_list.inc.htm

 

其他文件加载该文件的代码如下,比如列表页

<!-- class 中的 threadlist 保留,为前台管理使用 -->
<ul class="threadlist list-group list-group-flush shadow">
    <?php include _include(APP_PATH . 'view/htm/thread_list.inc.htm');?>
</ul>

 

thread_list.inc.htm 文件 此文件包含了管理代码,如果不需要前台管理,可删除掉管理代码,以下为该文件代码

 
<!-- thread 为写好的每天标题下的分割底线 tap 为移动端点击整行跳转 data-href="" 为整行跳转路径 tid="" 为前台管理时使用的ID -->
<?php if($threadlist) { foreach($threadlist as &$_thread) { ?>
<li class="media thread tap bg-white" data-href="<?php echo $_thread['url']; ?>" tid="<?php echo $_thread['tid'];?>">

    <!-- 此处为前台管理使用表单 -->
    <?php if($_thread['allowtop']) { ?>
    <div class="custom-control custom-checkbox ml-2">
        <input class="custom-control-input" type="checkbox" id="modtid-<?php echo $_thread['tid']; ?>" name="modtid" value="<?php echo $_thread['tid']; ?>" />
        <label class="custom-control-label custom-checkbox" for="modtid-<?php echo $_thread['tid']; ?>">
        </label>
    </div>
    <?php } ?>

    <div class="media-body">
        <div class="media">

            <!-- 此处代码为加载主题缩略图 开始 -->
            <?php if ($_thread['icon']) { ?>
            <div class="col-4 col-md-3">
                <a href="<?php echo $_thread['url']; ?>" <?php echo (10==$_thread['type']?'rel="nofollow" target="_blank"':''); ?>>
                    <img class="d-block w-100 rounded" src="<?php echo $_thread['icon_fmt'];?>" title='<?php echo $_thread['subject'];?>' alt='<?php echo $_thread['subject'];?>' />
                </a>
            </div>
            <?php } ?>
            <!-- 此处代码为加载主题缩略图 结束 -->

            <div class="media-body">
                <div class="col-lg-12 subject">

                    <!-- 此处为显示置顶字样 --> 
                    <?php if($_thread['sticky'] > 0) {?>
                    <span class="mr-2 font-weight-bold badge badge-<?php echo $_thread['sticky_class'];?>">
                        Sticky <!-- Sticky可改成置顶两个字 --> 
                    </span>
                    <?php } ?>

                    <!-- 此处为显示主题是否被锁 --> 
                    <?php if($_thread['closed'] > 0) { ?>
                    <span class="mr-2">
                        <i class="icon-lock text-<?php echo 1==$_thread['closed']?'danger':'dark';?>"></i>
                    </span>
                    <?php } ?>

                    <!-- 此处为主题 原样复制即可,此处有主题外链跳转 -->
                    <h2 class="h6 text-break font-weight-bold d-inline">
                        <a href="<?php echo $_thread['url']; ?>" aria-label="<?php echo $_thread['subject'];?>" <?php echo (10==$_thread['type']?'rel="nofollow" target="_blank"':''); ?>>
                        <?php echo $_thread['subject'];?>
                        </a>
                    </h2>

                    <?php if($_thread['files'] > 0) { ?>
                    &nbsp;<i class="icon small filetype other"></i>&nbsp;
                    <?php } ?>
                </div>

                <!-- 此处为摘要 -->
                <?php if($_thread['brief']){?>
                <div class="col-lg-12 text-break text-muted brief mt-2">
                    <?php echo $_thread['brief'];?>
                </div>
                <?php }?>

                <!-- 此处为tag 开始 -->
                <?php if($_thread['tag']){?>
                <div class="tag col-lg-12 text-break d-none d-md-block small text-muted mt-3">
                    <i class="icon-tags mr-2"></i>

                    <!-- 循环输出tag 开始 -->
                    <?php foreach($_thread['tag_fmt'] as $key => $_tag) {?>
                    <span class="mr-2">
                        <strong class="mb-0">
                            <a class="text-secondary" href="<?php echo url('tag-'.$key);?>">
                                <?php echo $_tag;?>
                            </a>
                        </strong>
                    </span>
                    <?php }?>
                    <!-- 循环输出tag 结束 -->

                </div>
                <?php }?>
                <!-- 此处为tag 结束 -->

                <div class="col-lg-12 text-grey mt-2">
                    <!-- 此处为发表主题者头像 -->
                    <a href="<?php echo url('user-' . $_thread['uid']);?>" tabindex="-1" class="mr-2">
                        <img class="avatar-1" src="<?php echo $_thread['user_avatar_url'];?>">
                    </a>

                    <!-- 此处为发表主题者昵称 -->
                    <span class="username mr-1" uid="<?php echo $_thread['uid'];?>">
                        <?php echo $_thread['username'];?>
                    </span>

                    <!-- 此处为发表主题时间 如需要显示年月日 改为 $_thread['create_date_fmt_ymd'] -->
                    <span class="date hidden-sm">
                        <?php echo $_thread['create_date_fmt'];?>
                    </span>

                    <?php if($_thread['lastuid']) { ?>
                    <span class="hidden-sm">
                        <span class="mx-1">←</span>
                        <span class="username mr-1" uid="<?php echo $_thread['lastuid'];?>">
                            <!-- 此处为最后评论该主题的人 -->
                            <?php echo $_thread['lastusername'];?>
                        </span>

                        <span>
                            <!-- 此处为最后评论该主题的时间 -->
                            <?php echo $_thread['last_date_fmt'];?>
                        </span>
                    </span>
                    <?php } ?>

                    <div class="float-right text-muted small">
                        <span class="mr-2 hidden-sm">
							<i class="icon-eye mr-1"></i>
                            <!-- 此处为主题被浏览次数 -->
                            <?php echo format_number($_thread['views']);?>
						</span>
                        <!--{hook thread__list_inc_views_after.htm}-->
                        <span class="mr-2">
							<i class="icon-comment-o mr-1"></i>
                            <!-- 此处为主题被评论次数 -->
                            <?php echo $_thread['posts'];?>
						</span>

                        <!-- 此处为编辑主题 -->
                        <?php if($_thread['allowupdate']) { ?>
                        <!--<span data-href="<?php echo url('content-update-' . $_thread['tid']); ?>" class="text-grey update-thread"><i class="icon-edit"></i> <?php echo lang('edit');?></span>-->

                        <?php } ?>

                        <!-- 此处为删除主题 -->
                        <?php if($_thread['allowdelete']) { ?>
                        <!--<span data-href="<?php echo url('operate-delete-' . $_thread['tid']);?>" class="text-grey delete-thread"><i class="icon-remove"></i> <?php echo lang('delete');?></span>-->
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</li>
<?php }} else { ?>
<li class="list-group-item">
    <!-- 此处为没有主题时显示 -->
    <div><?php echo lang('none');?></div>
</li>
<?php } ?>
0