• hi,

    i finally found the following script. But now i can’t get my menu working with CSS. So I need a little bit of help. Can someone give me a start how to make this menu work? (no bullets en under each other is enough)

    <div id="navigatie">
    <?php
    	// is there a page or category? both may have childeren
    	if( is_category() ) {
    		// if this category has childeren
    		$categ_object = get_category( get_query_var( 'cat' ), false );
    		$list_subcats = wp_list_categories( 'title_li=&depth=1&echo=0&child_of=' . (int)$categ_object->cat_ID );
    		// wordpress never returns null or empty string. If children, <a> tag will be found, otherwise string is returned.
    		preg_match_all( '|<a.*?href=[\'"](.*?)[\'"].*?>|i', $list_subcats, $m );
    		if( !$m[ 1 ] ) {
    			// there are no subcategories. Why?
    			// this is either the last child or this category really doesn't have subcategories
    			// last child must have a parent, right?
    				if( (int)$categ_object->category_parent > 0 ) {
    					// we'll need parent category name for the title, extract name via category ID
    					$parent_cat_name = $wpdb->get_var( "SELECT name FROM $wpdb->terms WHERE term_id=" . (int)$categ_object->category_parent );
    ?>
    					<div class="box">
    					<h3><?php echo $parent_cat_name; ?></h3>
    					<ul class="subnavigation">
    					<?php wp_list_categories( 'title_li=&depth=1&child_of=' . (int)$categ_object->category_parent ); ?>
    					</ul>
    					</div>
    <?php
    				} // else...no else! This category really doesn't have child categories.
    		} else {
    			// ohoho! ...but here are some. List them all...
    ?>
    			<div class="box">
    			<h3><?php echo $categ_object->cat_name; ?></h3>
    			<ul class="subnavigation">
    			<?php wp_list_categories( 'title_li=&depth=1&child_of=' . (int)$categ_object->cat_ID ); ?>
    			</ul>
    			</div>
    <?php
    		}
    	}
    	// almost the same for page hierarchy.
    	if( is_page() ) {
    		// here we go...just do the same job
    		$page_object = get_post( get_query_var( 'page' ), OBJECT );
    		$list_subpages = wp_list_pages( 'title_li=&depth=1&echo=0&child_of=' . (int)$page_object->ID );
    		// wordpress never returns null or empty string. If children, <a> tag will be found, otherwise string is returned.
    		preg_match_all( '|<a.*?href=[\'"](.*?)[\'"].*?>|i', $list_subpages, $ms );
    		if( !$ms[ 1 ] ) {
    			if( (int)$page_object->post_parent > 0 ) {
    				$parent_post_name = $wpdb->get_var( "SELECT post_title FROM $wpdb->posts WHERE ID=" . (int)$page_object->post_parent );
    ?>
    				<div class="box">
    				<h3><?php echo $parent_post_name; ?></h3>
    				<ul class="subnavigation">
    				<?php wp_list_pages( 'title_li=&depth=1&child_of=' . (int)$page_object->post_parent ); ?>
    				</ul>
    				</div>
    <?php
    			}
    		} else {
    ?>
    				<div class="box">
    				<h3><?php echo $page_object->post_title; ?></h3>
    				<ul class="subnavigation">
    				<?php wp_list_pages( 'title_li=&depth=1&child_of=' . (int)$page_object->ID ); ?>
    				</ul>
    				</div>
    <?php
    		}
    	}
    ?>
    </div>
  • The topic ‘A CSS Menu by this List (script)’ is closed to new replies.