TP5指定讲师页面文章上下篇

控制器代码 

// 查询上下篇
        $courseIds = model('course')
            ->where([
                'isdel' => 0,
                'teacherid' => $teacher['id'],
                'ispublic' => 1
            ])
            ->order('sort desc')
            ->order('view desc')
            ->column('id');
        $cidKey = array_search($cid, $courseIds);
        $preCourseId = array_key_exists($cidKey+1, $courseIds) ? $courseIds[($cidKey +1)] : false;
        $nexCourseId = array_key_exists($cidKey-1, $courseIds) ? $courseIds[($cidKey -1)] : false;

        $this->assign([
            'course' => $course,
            'preCourseId' => $preCourseId,
            'nexCourseId' => $nexCourseId,
            'model' => new CourseModel
        ]);

 模板代码

{{if condition="$preCourseId !== false"}}
<div>
     <span class="font-bold">上一篇:</span><a href="{{:url('index/teacher/cindex', ['cid' => $preCourseId])}}">{{$model->get($preCourseId)['title']}}</a>
</div>
{{/if}}
{{if condition="$nexCourseId !== false"}}
<div>
    <span class="font-bold">下一篇:</span><a href="{{:url('index/teacher/cindex', ['cid' => $nexCourseId])}}">{{$model->get($nexCourseId)['title']}}</a>
</div>
{{/if}}
原文地址:https://www.cnblogs.com/init-007/p/11685152.html