2018-05-29  380 views 评论

WordPress通过SQL语句获取所有有效文章的固定链接 伪静态

语句主要如下,通过一次子查询作为字表,随后关联post文章表查得。

SELECT E.ID,CONCAT('http://www.51softs.com/',T.slug,'/',E.post_name,'.html') AS 'Url',E.post_title,E.post_name,E.post_status,T.slug,T.taxonomy FROM qianzhui_posts E 
LEFT JOIN (
SELECT A.object_id,B.term_taxonomy_id,C.`name`,C.slug,B.taxonomy FROM qianzhui_term_relationships A
LEFT JOIN qianzhui_term_taxonomy B ON A.term_taxonomy_id = B.term_taxonomy_id
LEFT JOIN qianzhui_terms C ON B.term_id = C.term_id
WHERE B.taxonomy='category') T
ON E.ID = T.object_id
WHERE E.post_status='publish' AND E.ping_status='open' AND E.post_type='post'
GROUP BY E.ID

我的固定链接格式是 域名 + 分类名称 + 固定名称(post_name),实际应根据具体需求来写。

给我留言

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: