• Resolved wilfswann

    (@wilfswann)


    This should be fairly simple but I’ve searched for hours in vein.

    I’m trying to do something similar to this https://nettuts.s3.amazonaws.com/196_jquery/index.htm so that I can hide or display groups of pages in a list. To do that I need to assign classes to each of my pages, I’ve tried using the Classy wp_list_pages plugin but that assigns every page with a different class, I need to be able to assign the same class to a group of the links. I also need to be able to assign multiple classes to each list item.

    I could hard code it but then I would need to manually change either the CSS or the markup every time I added a new page. Anyone have any ideas to fix this conundrum?

Viewing 5 replies - 31 through 35 (of 35 total)
  • Thread Starter wilfswann

    (@wilfswann)

    thank you so so much for your help. I know I have already asked too much of you but it is possible to list all the pages with the ‘myclass’ key regardless of the value and then set the value as the class?

    not sure if maybe you can just get rid of the '&meta_value=' . $value . part or if there is something more fundamental to it.

    Thread Starter wilfswann

    (@wilfswann)

    okay I think I worked out how to do that myself by removing a few things from the code. Works exactly how I wanted it to, thanks heaps!

    Moderator keesiemeijer

    (@keesiemeijer)

    function get_my_pages($id, $key='', $class='') {
    	if($key !='') {
    		$parentID = ($id == '') ? '' : '&child_of='.$id;
    		$my_pages = get_pages('meta_key=' . $key . $parentID);
    		$html= '';
                    if(!empty($my_pages)){
    		$html .= '<ul>' . "\n";
                      foreach ($my_pages as $pagg) {
      	    	  $html .=  '<li class="' . $class . '"><a href="';
      	    	  $html .=  get_page_link($pagg->ID) . '">';
      	    	  $html .=  $pagg->post_title . '</a></li>' . "\n";
                      }
                   $html .= '</ul>' . "\n";
                   return $html;
                   }
            }
    }

    I think you mean this
    first value = parent ID (if meta_key is in a child page)
    second value ($key)= the meta_key
    third ($class)= class off li
    I changed the values a bit ($class to $key)
    call the function like so
    <?php echo get_my_pages(65, 'myclass', 'whatever'); ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    Glad we got it working! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

    Thread Starter wilfswann

    (@wilfswann)

    I changed the function a bit to

    function get_my_pages($id, $key='') {
    	if($key !='') {
    		$parentID = ($id == '') ? '' : '&child_of='.$id;
    		$my_pages = get_pages('meta_key=' . $key . $parentID);
    		$html= '';
                    if(!empty($my_pages)){
    		$html .= '<ul>';
                      foreach ($my_pages as $pagg) {
      	    	  $html .=  '<li class="' . $pagg->meta_value . '"><a href="' . get_page_link($pagg->ID) . '">';
      	    	  $html .=  $pagg->post_title . '</a></li>';
                      }
                   $html .= '</ul>';
                   return $html;
                   }
            }
    }

    So that you don’t need to specify the class of the list, you get a list of all of the pages which is exactly what I was looking for. It seems to work perfectly so I’m a happy bunny, thanks again.

Viewing 5 replies - 31 through 35 (of 35 total)
  • The topic ‘wp_list_pages Classes’ is closed to new replies.