优化代码
This commit is contained in:
parent
11e0c32c6f
commit
9c89f44841
|
@ -1,7 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/fthvgb1/wp-go/helper/number"
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||||
|
@ -17,6 +17,7 @@ var commonClass = map[int]string{
|
||||||
constraints.Category: "archive category ",
|
constraints.Category: "archive category ",
|
||||||
constraints.Tag: "archive category ",
|
constraints.Tag: "archive category ",
|
||||||
constraints.Search: "search ",
|
constraints.Search: "search ",
|
||||||
|
constraints.Author: "archive author ",
|
||||||
constraints.Detail: "post-template-default single single-post ",
|
constraints.Detail: "post-template-default single single-post ",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,38 +26,40 @@ func (h *Handle) CalBodyClass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) BodyClass(class ...string) string {
|
func (h *Handle) BodyClass(class ...string) string {
|
||||||
s := ""
|
|
||||||
if constraints.Ok != h.Stats {
|
if constraints.Ok != h.Stats {
|
||||||
return "error404"
|
return "error404"
|
||||||
}
|
}
|
||||||
switch h.Scene {
|
switch h.Scene {
|
||||||
case constraints.Search:
|
case constraints.Search:
|
||||||
s = "search-no-results"
|
s := "search-no-results"
|
||||||
if len(h.GinH["posts"].([]models.Posts)) > 0 {
|
if len(h.Index.Posts) > 0 {
|
||||||
s = "search-results"
|
s = "search-results"
|
||||||
}
|
}
|
||||||
|
class = append(class, s)
|
||||||
case constraints.Category, constraints.Tag:
|
case constraints.Category, constraints.Tag:
|
||||||
cat := h.C.Param("category")
|
cat := h.Index.Param.Category
|
||||||
if cat == "" {
|
|
||||||
cat = h.C.Param("tag")
|
|
||||||
}
|
|
||||||
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool {
|
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool {
|
||||||
return my.Name == cat
|
return my.Name == cat
|
||||||
})
|
})
|
||||||
if cate.Slug[0] != '%' {
|
if cate.Slug[0] != '%' {
|
||||||
s = cate.Slug
|
class = append(class, str.Join("category-", cate.Slug))
|
||||||
}
|
}
|
||||||
s = fmt.Sprintf("category-%v category-%v", s, cate.Terms.TermId)
|
class = append(class, str.Join("category-", number.ToString(cate.Terms.TermId)))
|
||||||
case constraints.Detail:
|
|
||||||
s = fmt.Sprintf("postid-%d", h.GinH["post"].(models.Posts).Id)
|
case constraints.Author:
|
||||||
if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 {
|
author := h.Index.Param.Author
|
||||||
s = str.Join(s, " single-format-standard")
|
user, _ := cache.GetUserByName(h.C, author)
|
||||||
}
|
class = append(class, str.Join("author-", number.ToString(user.Id)))
|
||||||
}
|
if user.UserLogin[0] != '%' {
|
||||||
if s != "" {
|
class = append(class, str.Join("author-", user.UserLogin))
|
||||||
class = append(class, s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case constraints.Detail:
|
||||||
|
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
|
||||||
|
if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 {
|
||||||
|
class = append(class, "single-format-standard")
|
||||||
|
}
|
||||||
|
}
|
||||||
if wpconfig.IsCustomBackground(h.Theme) {
|
if wpconfig.IsCustomBackground(h.Theme) {
|
||||||
class = append(class, "custom-background")
|
class = append(class, "custom-background")
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,6 +210,7 @@ func (i *IndexParams) parseAuthor() (err error) {
|
||||||
i.Where = append(i.Where, []string{
|
i.Where = append(i.Where, []string{
|
||||||
"post_author", "=", strconv.FormatUint(user.Id, 10), "int",
|
"post_author", "=", strconv.FormatUint(user.Id, 10), "int",
|
||||||
})
|
})
|
||||||
|
i.Header = str.Join("作者:", username)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user