[BUGFIX] blog get right post and order of posts
This commit is contained in:
parent
14ff889bba
commit
e3886606fc
|
@ -8,6 +8,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
||||||
web "dev.sum7.eu/sum7/warehost/modul/web"
|
web "dev.sum7.eu/sum7/warehost/modul/web"
|
||||||
)
|
)
|
||||||
|
@ -106,9 +108,11 @@ func handlerfunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if !dbconnection.Where(page).First(&page).RecordNotFound() {
|
if !dbconnection.Where(page).First(&page).RecordNotFound() {
|
||||||
page.URL = urlObj
|
page.URL = urlObj
|
||||||
} else {
|
} else {
|
||||||
if !dbconnection.Where(blog).Preload("Posts").First(&blog).RecordNotFound() {
|
if !dbconnection.Where(blog).Preload("Posts", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Order("createat DESC")
|
||||||
|
}).First(&blog).RecordNotFound() {
|
||||||
blogpost.BlogID = blog.ID
|
blogpost.BlogID = blog.ID
|
||||||
if urlObj.Path != blogpost.Title && ((blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2)) {
|
if (blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2) {
|
||||||
db := dbconnection.Where(blogpost).Where("LOWER(title) = LOWER(?)", urlParts[len(urlParts)-1])
|
db := dbconnection.Where(blogpost).Where("LOWER(title) = LOWER(?)", urlParts[len(urlParts)-1])
|
||||||
if blog.PostURL == 1 {
|
if blog.PostURL == 1 {
|
||||||
db = db.Where("to_char(createat,'YYYY-MM') = ?", strings.Join(urlParts[len(urlParts)-3:len(urlParts)-1], "-"))
|
db = db.Where("to_char(createat,'YYYY-MM') = ?", strings.Join(urlParts[len(urlParts)-3:len(urlParts)-1], "-"))
|
||||||
|
|
Reference in New Issue