本文整理匯總了Golang中github.com/lisijie/goblog/models.Post.OrderBy方法的典型用法代碼示例。如果您正苦於以下問題:Golang Post.OrderBy方法的具體用法?Golang Post.OrderBy怎麽用?Golang Post.OrderBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lisijie/goblog/models.Post
的用法示例。
在下文中一共展示了Post.OrderBy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Index
//首頁, 隻顯示前N條
func (this *MainController) Index() {
var (
list []*models.Post
pagesize int
err error
page int
)
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 10
}
query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0)
count, _ := query.Count()
if count > 0 {
query.OrderBy("-istop", "-posttime").Limit(pagesize, (page-1)*pagesize).All(&list)
}
this.Data["count"] = count
this.Data["list"] = list
this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "").ToString()
this.setHeadMetas()
this.display("index")
}
示例2: Archives
//曆史歸檔
func (this *MainController) Archives() {
var (
page int
pagesize int
err error
count int64
result map[string][]*models.Post
)
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 20
} else {
pagesize *= 2
}
query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0)
count, _ = query.Count()
result = make(map[string][]*models.Post)
if count > 0 {
var list []*models.Post
query.OrderBy("-posttime").Limit(pagesize, (page-1)*pagesize).All(&list)
for _, v := range list {
year := v.Posttime.Format("2006")
if _, ok := result[year]; !ok {
result[year] = make([]*models.Post, 0)
}
result[year] = append(result[year], v)
}
}
this.Data["page"] = page
this.Data["count"] = count
this.Data["pagesize"] = pagesize
this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "/archives").ToString()
this.Data["result"] = result
this.setHeadMetas("歸檔")
this.display("archives")
}