Wednesday, 15 May 2013

navigation - WordPress Page Walker class descendants of parent with thumbnail and custom classes -


Please, help!

I am at the end of my mind and will have to finish it by tomorrow, so I appreciate any help in adjusting the Walker class on this page Really . (Please!)

The final goal is to display a list in this format:

  Animals are not shown + cats - dogs - bulldog - boxer - poodle + horse + Sheep     Should not be displayed.  

Markup requirements

I need the following markup in the final output:

  & lt; Ul class = "list" & gt; & Lt; Li class = "list__items" & gt; & Lt; A href = "#link" & gt; Cats & lt; / Li & gt; & Lt; Li class = "list__items" & gt; & Lt; A href = "#link" & gt; Dogs & lt; / A & gt; & Lt; Ul class = "sub-tier__list" & gt; & Lt; Li class = "sub-level group" & gt; & Lt; A href = "#link" & gt; Bulldogs & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "sub-level group" & gt; & Lt; A href = "#link" & gt; Boxer & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "sub-level group" & gt; & Lt; A href = "#link" & gt; Poodles & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt;  

There are other divisions, headings, etc. inside the sub-thier_ group, but I wanted to keep it clean for presentation purposes.


My current page walker class:

  class Page_List_With_Thumbnail extends Walker_Page {function start_lvl (& amp; $ output, $ depth) {$ Indent = str_arapet ("\ t", $ depth); $ Output = "Indent \ N $ & lt; ul & gt; \ n"; } Function start_el (& amp; $ output, $ page, $ depth, $ argons, $ current_page) {if ($ depth) $ indent = str_arpet ("\ t", $ depth); And $ indent = ''; Remove ($ ARJ, ExtraCipIP); $ Class_attr = ''; If (! $ (Current_page) below) {$ _current_page = get_page ($ current_page); If ((isset ($ _ current_page- & gt; ancestors) & amp; amp; amp; & amp; amp; amp; in_array ($ page-> ID, array ($ _current_page- & gt; ancestors)) ($ page- & gt; ; Id == $ current_page) || ($ _current_page and $ page- & gt; id == $ _current_page- & gt; post_perrent)) {$ class_attr = 'sel'; }} Otherwise ((is_single)) is_archive ()) & amp; Amp; ($ Page-> ID == get_option ('page_for_posts'))) {$ class_attr = 'sel'; } If $ ($ class_attr! = '') {$ Class_attr = 'class = "'. $ Class_attr. '' '; $ Link_ before. =' & Lt; strong & gt; '; $ Link_after =' & lt ; / Strong> $ Link_after;} // thumbnail $ page_thumbnail = get_the_post_thumbnail ($ page-> ID); $ output. $ $ Indent '& lt; li' $ class_attr '& gt; & lt; a href = "' get_page_link ( $ Page- & gt; ID). '' '$ Class_attr' '& Gt; '$ Link_after $ Link_after $ Link_s before Apply_filters ('the_title', $ page-> post_title, $ page-> ID). $ Link_after & Lt; / A & gt; ';}}  

My current template markup:

  & lt ;? Php $ walker = new Page_List_With_Thumbnail (); If ($ post- & gt; post_parent) $ children = wp_list_pages (array ('title_li' = & gt; '', 'child_of' => = post- & gt; post_perrent, 'resonance' = & gt; 0 ',' depth '=>' 0 ',' walker '=> $ walker)); And $ children = wp_list_pages ("title_li = & child_of =". $ Post-> ID. "& Amp; echo = 0"); If ($ children) {? & Gt; & Lt; Ul & gt; & Lt; Php echo $ children ;; & Gt; & Lt; / Ul & gt; & Lt ;? Php}? & Gt;  

Bonus: thumbnail output

Currently, Get_the_post_thumbnail ($ page-> ID); For good measure, but if I can exclude alt, the title shows the titles as separate headings, which must be broken on nightmare cake .


I have tried my best to collect things here (and 4 million other Google searches) so I hope that this is a simple improvement

lot thanks a lot!


No comments:

Post a Comment