From e1c1da608368864f46ca7574d18a48d961cca8c9 Mon Sep 17 00:00:00 2001 From: xing Date: Mon, 20 Mar 2023 23:41:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pkg/dao/common.go | 7 ++++++- internal/theme/wp/components/widget/category.go | 17 +++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/pkg/dao/common.go b/internal/pkg/dao/common.go index 7168424..a9bda22 100644 --- a/internal/pkg/dao/common.go +++ b/internal/pkg/dao/common.go @@ -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"}, }), diff --git a/internal/theme/wp/components/widget/category.go b/internal/theme/wp/components/widget/category.go index ac563df..a8a56e2 100644 --- a/internal/theme/wp/components/widget/category.go +++ b/internal/theme/wp/components/widget/category.go @@ -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(`" - } +func CategoryLi(h *wp.Handle, conf map[any]any, categories []models.TermsMy) string { s := str.NewBuilder() - s.WriteString("