Loda Sabbin Labarai ta Categangare ta hanyar Menu na WordPress ta amfani da kayan jQuery

jquery

Idan ka ziyarci wasu manyan blogs a can kamar Mashable, Kuna iya lura cewa suna da tsarin menu mai kyau wanda ya fadi kasa kuma ya samar muku da ganuwa a cikin sabbin rubutun blog daga kowane bangare. Don tabbatar da cewa shafin ba zai dauke shi ba har abada, sun loda wannan abin da suke amfani da Ajax… kuma sai su loda shi kawai bayan shafin ya cika.

WordPress Ajax Submenu

Muna so muyi haka a nan Martech Zone. Don ba da ɗan haske game da rukunonin da muke da su, Ina so in nuna wasu sakonni a cikin kowane. Muna da masaniya a WordPress, da WordPress API da jQuery amma har sai da na sami labarin akan Samun Rubutu ta Categangare ta amfani da jQuery cewa mun sami kyakkyawan bayani.

SAURARA: Wani bangare na hanyar su wacce banyi imani da ita ba itace kyakkyawar mafita itace wuce duk tambarin_post din ta hanyar JavaScript… da alama a wurina kana bude kanka ne dan satar bayanan mutane! Na canza rubutun wannan rukunin yanar gizon don kawai in wuce sigogin da ake bukata a cikin umarnin query_posts.

Koyarwar tana amfani da mai amfani ta hanyar ƙirƙirar samfuri don jan hankali a cikin sakonnin, sannan kuma yadda za'a gina hanyoyin haɗin gwiwa waɗanda zasu iya fara buƙatar. Zai kasance da sauƙi idan muna son kawai sanya wasu hanyoyin, amma a zahiri muna so mu yi amfani da WordPress 'wanda aka gina a cikin menu na kewayawa. Abin baƙin ciki a gare mu, hanyoyin haɗin menu na WordPress sun samar da lambobi yayin da kuke ƙarawa da cire abubuwan menu… amma a zahiri basu da wani bayani game da rukunin da kuke so ku ja ku wucewa a cikin kiranku na Ajax.

Domin yiwa jerin abubuwan menu lakabi da kyau, mun sanya lambar daga WPreso, Sanya ajujuwan aji / post slug zuwa ajin abubuwan menu.

Matsala guda ɗaya kawai… tana aiki don shafi ko post, amma a zahiri bai yi aiki ba don Kategorien! Don haka mun sabunta buƙatun don tutsar sulug tare da:

$ slug = get_cat_slug ($ id);

Kuma ya ƙara aikin daga WPRecipes, Dabarar WordPress: Samu samfurin tarkace ta amfani da ID na rukuni, don sake dawo da rukunin jinsin cikin sifar data a cikin menu na kewayawa.

Don haka… godiya ga kokarin haɗin gwiwa na shafukan 3 WordPress da wasu abubuwan gyara ta jQuery guru a DK New Media, Stephen Coley (don sassauƙa menu), muna da tsarin ƙaramin menu mai kyau!

Duk aikin anyi shi cikin fayilolin jigon mu. Mun loda matatun menu na kewayawa a cikin ayyuka.php, sun ƙara submenu div a cikin taken taken taken.php ɗinmu, mun ƙara samfuri a garemu, sannan mun loda wani ƙaramin fayil ɗin JavaScript a cikin takenmu - tabbatar da cewa an riga an ɗora jQuery a cikin jigonmu kazalika. Fata za ku yaba da aikin, ya kasance abin sabuntawa ga shafin!

8 Comments

  1. 1

    Kuna nuna ko siyar da wannan lambar a wani wuri? Na jima ina kokarin sa abin yayi aiki amma ban iya gano yadda ake saka wp_nav_menu tare da mai tafiya ba…

  2. 6
  3. 8

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.