小优化

This commit is contained in:
xing 2023-03-20 23:41:57 +08:00
parent ab56f45790
commit e1c1da6083
2 changed files with 17 additions and 7 deletions

View File

@ -42,10 +42,15 @@ func CategoriesAndTags(a ...any) (terms []models.TermsMy, err error) {
if !helper.GetContextVal(ctx, "showCountZero", false) {
w = append(w, []string{"tt.count", ">", "0", "int"})
}
order := []string{"name", "asc"}
ord := helper.GetContextVal[[]string](ctx, "order", nil)
if ord != nil {
order = ord
}
terms, err = model.Finds[models.TermsMy](ctx, model.Conditions(
model.Where(w),
model.Fields("t.term_id"),
model.Order(model.SqlBuilder{{"t.name", "asc"}}),
model.Order(model.SqlBuilder{order}),
model.Join(model.SqlBuilder{
{"t", "inner join", "wp_term_taxonomy tt", "t.term_id = tt.term_id"},
}),

View File

@ -76,13 +76,8 @@ func Category(h *wp.Handle) string {
return h.ComponentFilterFnHook(widgets.Categories, str.Replace(t, args))
}
func categoryUL(h *wp.Handle, args map[string]string, conf map[any]any, categories []models.TermsMy) string {
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{title}"])
args["{$navCloser}"] = "</nav>"
}
func CategoryLi(h *wp.Handle, conf map[any]any, categories []models.TermsMy) string {
s := str.NewBuilder()
s.WriteString("<ul>\n")
isCount := conf["count"].(int64)
currentCate := models.TermsMy{}
if h.Scene() == constraints.Category {
@ -118,7 +113,17 @@ func categoryUL(h *wp.Handle, args map[string]string, conf map[any]any, categori
r := m[0]
categoryLi(r, cate, tree.Ancestor(m, 0, cate), isCount, s)
}
return s.String()
}
func categoryUL(h *wp.Handle, args map[string]string, conf map[any]any, categories []models.TermsMy) string {
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{title}"])
args["{$navCloser}"] = "</nav>"
}
s := str.NewBuilder()
s.WriteString("<ul>\n")
s.WriteString(CategoryLi(h, conf, categories))
s.WriteString("</ul>")
return s.String()
}