超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優(yōu)惠信息
衡天云優(yōu)惠活動
熱網(wǎng)互聯(lián)2026年促銷活動
hostkvm優(yōu)惠促銷活動
zji優(yōu)惠促銷活動
QQGNET優(yōu)惠促銷活動
QQGNET優(yōu)惠促銷活動

WordPress是如何實現(xiàn)相關文章的功能的?分享的幾種方法(wordpress文章編輯器)

主機參考:VPS測評參考推薦/專注分享VPS服務器優(yōu)惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情!
我們發(fā)布的部分優(yōu)惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作

WordPress是如何實現(xiàn)相關文章的功能的?下面這篇文章介紹了WordPress代碼實現(xiàn)相關文章的幾種方式,希望對你有所幫助!

WordPress是如何實現(xiàn)相關文章的功能的?分享的幾種方法(wordpress文章編輯器)

很多WordPress插件都可以實現(xiàn)相關文章的功能。插件的好處是配置簡單,但是可能會對網(wǎng)站的速度產(chǎn)生一些小的影響。所以很多人更喜歡用代碼來實現(xiàn)所需的功能。不過話說回來,代碼實現(xiàn)也有缺點,就是配置復雜,不懂代碼的人完全糊涂或者只能抄襲別人的代碼,不如用插件。

在這里,我整理了幾種用代碼實現(xiàn)相關文章的方法,會詳細注明代碼各部分的功能,以及如何定制自己想要的功能,希望對大家有所幫助。在我們開始之前,很清楚以下所有方法輸出的HTML代碼格式都是以下形式,您可以根據(jù)需要修改它們:

& ltul id = & quotxxx & quot& gt& lt李& gt* & lta title = & quot文章標題1 & quotrel = & quot書簽& quothref = & quot文章鏈接1 & quot& gt文章標題1

& ltul id = & quot標簽_相關& quot& gt& lt?phpglobal $ post$ post _ tags = WP _ get _ post _ tags($ post-& gt;ID);if($ post _ tags){ foreach($ post _ tags as $ tag){//獲取標記列表$tag_list[]。= $ tag-& gt;術語標識;}//隨機獲取標簽列表中的一個標簽$ post _ tag = $ tag _ list [mt _ rand (0,count($ tag _ list)-1)];//此方法使用query_posts()函數(shù)調(diào)用相關文章。下面是參數(shù)列表$ args = array(& # 39;標簽_ _ in & # 39= & gt數(shù)組($post_tag),& # 39;類別_ _ not _ in & # 39= & gt數(shù)組(空),//排除的類別ID & # 39post _ _ not _ in & # 39= & gt數(shù)組($ post->;ID)、& # 39;海報& # 39;= & gt6.//顯示相關文章的數(shù)量& # 39;caller _ get _ posts & # 39= & gt1 );query _ posts($ args);if(have _ posts()){ while(have _ posts()){ the _ post();update _ post _ cache($post);?& gt& lt李& gt* & lta href = & quot& lt?PHP the _ permalink();?& gt"rel = & quot書簽& quottitle = & quot& lt?PHP the _ title _ attribute();?& gt"& gt& lt?PHP the _ title();?& gt& lt/a & gt;& lt/李& gt& lt?php } } else { echo & # 39& lt李& gt*暫時沒有相關文章

方法二:分類關聯(lián)這種方法是通過獲取文章的分類id,然后獲取該分類下的文章,從而獲取相關文章。

& ltul id = & quotcat _ related & quot& gt& lt?phpglobal $ post$ cats = WP _ get _ post _ categories($ post-& gt;ID);if($ cats){ $ args = array(& # 39;& # 39;中的類別_ _;= & gt數(shù)組($cats[0])、& # 39;post _ _ not _ in & # 39= & gt數(shù)組($ post->;ID)、& # 39;海報& # 39;= & gt6, 'caller _ get _ posts & # 39= & gt1 );query _ posts($ args);if(have _ posts()){ while(have _ posts()){ the _ post();update _ post _ cache($post);?& gt& lt李& gt* & lta href = & quot& lt?PHP the _ permalink();?& gt"rel = & quot書簽& quottitle = & quot& lt?PHP the _ title _ attribute();?& gt"& gt& lt?PHP the _ title();?& gt& lt/a & gt;& lt/李& gt& lt?php } } else { echo & # 39& lt李& gt*暫時沒有相關文章

& ltul id = & quot標簽_相關& quot& gt& lt?phpglobal $post,$ wpdb$ post _ tags = WP _ get _ post _ tags($ post-& gt;ID);if($ post _ tags){ $ tag _ list = & # 39;';Foreach ($post_tags as $tag) {//獲取標記列表$tag_list。= $ tag-& gt;術語標識。',';} $tag_list = substr($tag_list,0,strlen($ tag _ list)-1);$ related _ posts = $ wpdb-& gt;獲取結(jié)果(& quotSELECT DISTINCT ID,post _ title FROM { $ wpdb-& gt;前綴}文章,{ $ wpdb-& gt;前綴}term_relationships,{ $ wpdb-& gt;前綴}term_taxonomy,其中{$wpdb->prefix } term _ taxonomy . term _ taxonomy _ id = { $ wpdb-& gt;prefix } term _ relationships . term _ taxonomy _ ID AND ID = object _ ID AND taxonomy = & # 39;post _ tag & # 39而post _ status = & # 39出版& # 39;而post _ type = & # 39郵政& # 39;和term _ id(& quot;。$tag_list。")和ID!= '"。$ post->;身份證。"'ORDER BY RAND()LIMIT 6 & quot;);//在上面的代碼中,6用于限制只能訪問6篇相關文章//通過修改數(shù)字6,可以修改你想要的文章數(shù),如果($ related _ posts){ foreach($ related _ posts as $ related _ posts){?& gt& lt李& gt& lta href = & quot& lt?PHP echo get _ permalink($ related _ post-& gt;ID);?& gt"rel = & quot書簽& quottitle = & quot& lt?PHP echo $ related _ post-& gt;post _ title?& gt"& gt& lt?PHP echo $ related _ post-& gt;post _ title?& gt& lt/a & gt;& lt/李& gt& lt?php } } else { echo & # 39& lt李& gt暫時沒有相關的文章

& ltul id = & quotcat _ related & quot& gt& lt?phpglobal $post,$ wpdb$ cats = WP _ get _ post _ categories($ post-& gt;ID);if($ cats){ $ related = $ wpdb-& gt;獲取結(jié)果(& quotSELECT post_title,ID FROM { $ wpdb-& gt;前綴}文章,{ $ wpdb-& gt;前綴}term_relationships,{ $ wpdb-& gt;前綴}term_taxonomy,其中{$wpdb->前綴}帖子。ID = { $ wpdb-& gt;前綴}term_relationships.object_id和{ $ wpdb-& gt;prefix } term _ taxonomy . taxonomy = & # 39;類別& # 39;和{ $ wpdb-& gt;prefix } term _ taxonomy . term _ taxonomy _ id = { $ wpdb-& gt;前綴} term _ relationships . term _ taxonomy _ id和{ $ wpdb-& gt;prefix } posts.post _ status = & # 39出版& # 39;和{ $ wpdb-& gt;prefix } posts.post _ type = & # 39郵政& # 39;和{ $ wpdb-& gt;prefix } term _ taxonomy . term _ id = & # 39;"。$cats[0]。"'和{ $ wpdb-& gt;前綴}帖子。ID!= '"。$ post->;身份證。"'ORDER BY RAND()LIMIT 6 & quot;);if($ related){ foreach($ related as $ related _ post){?& gt& lt李& gt* & lta href = & quot& lt?PHP echo get _ permalink($ related _ post-& gt;ID);?& gt"rel = & quot書簽& quottitle = & quot& lt?PHP echo $ related _ post-& gt;post _ title?& gt"& gt& lt?PHP echo $ related _ post-& gt;post _ title?& gt& lt/a & gt;& lt/李& gt& lt?php } } else { echo & # 39& lt李& gt*暫時沒有相關文章

& ltul id = & quot作者_相關& quot& gt& lt?php global $ post$ post _ author = get _ the _ author _ meta(& # 39;user _ login & # 39);$ args = array(& # 39;作者姓名& # 39;= & gt$post_author,& # 39;post _ _ not _ in & # 39= & gt數(shù)組($ post->;ID)、& # 39;海報& # 39;= & gt6.//顯示相關文章的數(shù)量& # 39;orderby & # 39= & gt日期,//按時間排序& # 39;caller _ get _ posts & # 39= & gt1 );query _ posts($ args);if(have _ posts()){ while(have _ posts()){ the _ post();update _ post _ cache($post);?& gt& lt李& gt* & lta href = & quot& lt?PHP the _ permalink();?& gt"rel = & quot書簽& quottitle = & quot& lt?PHP the _ title _ attribute();?& gt"& gt& lt?PHP the _ title();?& gt& lt/a & gt;& lt/李& gt& lt?php } } else { echo & # 39& lt李& gt*暫時沒有相關文章

方法一:0.18067908287048秒方法二:0.0594690967秒方法三:0.07260400537秒方法四:0.04599秒方法五:0.0011秒。

推薦學習:WordPress教程

WordPress就是這樣實現(xiàn)相關文章功能的。分享方法詳情請關注主機參考其他相關文章!

這幾篇文章你可能也喜歡:

本文由主機參考刊發(fā),轉(zhuǎn)載請注明:WordPress是如何實現(xiàn)相關文章的功能的?分享的幾種方法(wordpress文章編輯器) http://m.k2270.com/91805.html

【騰訊云】領8888元采購禮包,搶爆款云服務器 每月 9元起,個人開發(fā)者加享折上折!
打賞
轉(zhuǎn)載請注明原文鏈接:主機參考 » WordPress是如何實現(xiàn)相關文章的功能的?分享的幾種方法(wordpress文章編輯器)
主機參考僅做資料收集,不對商家任何信息及交易做信用擔保,購買前請注意風險,有交易糾紛請自行解決!請查閱:特別聲明

評論 搶沙發(fā)

評論前必須登錄!