• Resolved LulaViolet

    (@lulaviolet)


    Hello WP-Fellow,

    Since a while I am trying to solve that little issue my menu has, I looked into forums, tried code by my self but i can’t find the solution, but I guess you can help me.

    I got a horizontal Menu, with a displayed horizontal submenu (in case the parent page has children) under that menu.
    Parent1
    Parent 2 (child 2.1, child 2.2)
    Parent 3
    I putted following code into the header.php

    <div id="untermenu" role="navigation">
    <?php /*wp_nav_menu( array( 'theme_location' => 'primary' ) );*/ ?>
    <ul>
    	<?php wp_list_pages('depth=1&sort_column=menu_order&title_li='); ?>
    </ul><br />
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul id="untermenu_untermenu">
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    		</div>

    Everything works fine, I just want that the ‘parent 2’ will be turned off as a page. When clicking on ‘parent 2’ you should directly go to the page of child 2.1.
    I tried the custom-menu thing with the # ass a link, but it doesn’t work nicely. I more like to code it, then you have more control over it.
    Any ideas which code I have to add to my already existing code?
    Thank you in advance.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi, LulaViolet.

    Try this. Add before <?php get_header(); ?> in page.php

    <?php $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
    if ($pagekids) {
    $firstchild = $pagekids[0];
    wp_redirect(get_permalink($firstchild->ID));
    }  ?>


    $pagekids[0] >> 0 must belongs to order number for page Child 2.1

    Thanks,

    Hanafi.

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey Mohamad Hanafi,

    Thank you for you reply.
    I tryed that code, but it doesn’t change my menu. I added it to the page.php before <?php get_header(); ?> and when that didn’t work, I also added it to the index.php, but nothing worked.
    I still get the parent as a page, when I am clicking on it. The submenu is open, but I have to click on the first child to activate it. In other words the parent still is a page on its own.
    The childpage order of Child 2.1 is 0.
    Did I make something wrong? Or did I forget anything?

    Thank you πŸ™‚

    Please retry.

    remove additional codes in header.php
    remove any setting to force it in index.php

    Just add my suggested code in page.php
    I applied this feature in my weblog; you can navigate to the second menu of my weblog.

    Thanks.

    Hanafi.

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey Hanafi,

    I’m sorry but I can’t find the solution. I’m not good enough to fully understand php code. It’s probably some line somewhere I have to remove, but I really don’t know which one. Maybe you can find it.

    Here’s my index.php code (I think it’s not in there, but who knows … )

    <?php
    /**
     * The main template file.
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     */
    
    get_header(); ?>
    
    		<div id="primary">
    			<div id="content" role="main">
    
    			<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    			<h2><?php the_title(); ?></h2>
    	<div class="beitrag">
    	<?php the_content(__('(more...)')); ?>
    	<?php edit_post_link(__('Edit This')); ?>
    	</div>
    
    	<?php endwhile; else: ?>
    	<p><?php _e('Sorry, but no.'); ?></p>
    	<?php endif; ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And here the code of my header.php.

    <?php
    /**
     * The Header for our theme.
     *
     * Displays all of the <head> section and everything up till <div id="main">
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    ?><!DOCTYPE html>
    <!--[if IE 6]>
    <html id="ie6" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if IE 7]>
    <html id="ie7" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if IE 8]>
    <html id="ie8" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if !(IE 6) | !(IE 7) | !(IE 8)  ]><!-->
    <html <?php language_attributes(); ?>>
    <!--<![endif]-->
    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <meta name="viewport" content="width=device-width" />
    <title><?php
    	/*
    	 * Print the <title> tag based on what is being viewed.
    	 */
    	global $page, $paged;
    
    	wp_title( '|', true, 'right' );
    
    	// Add the blog name.
    	bloginfo( 'name' );
    
    	// Add the blog description for the home/front page.
    	$site_description = get_bloginfo( 'description', 'display' );
    	if ( $site_description && ( is_home() || is_front_page() ) )
    		echo " | $site_description";
    
    	// Add a page number if necessary:
    	if ( $paged >= 2 || $page >= 2 )
    		echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );
    
    	?></title>
    <link rel="profile" href="http://gmpg.org/xfn/11" />
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
    <![endif]-->
    <?php
    	/* We add some JavaScript to pages with the comment form
    	 * to support sites with threaded comments (when in use).
    	 */
    	if ( is_singular() && get_option( 'thread_comments' ) )
    		wp_enqueue_script( 'comment-reply' );
    
    	/* Always have wp_head() just before the closing </head>
    	 * tag of your theme, or you will break many plugins, which
    	 * generally use this hook to add elements to <head> such
    	 * as styles, scripts, and meta tags.
    	 */
    	wp_head();
    ?>
    </head>
    
    <body <?php body_class(); ?>>
    <div id="page" class="hfeed">
    
    <header id="branding" role="banner">
    
    				<div id="site-title"></div>
    
    			<?php
    				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    				if ( $header_image ) :
    					// Compatibility with versions of WordPress prior to 3.4.
    					if ( function_exists( 'get_custom_header' ) ) {
    						// We need to figure out what the minimum width should be for our featured image.
    						// This result would be the suggested width if the theme were to implement flexible widths.
    						$header_image_width = get_theme_support( 'custom-header', 'width' );
    					} else {
    						$header_image_width = HEADER_IMAGE_WIDTH;
    					}
    					?>
    			<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
    				<?php
    					// The header image
    					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
    					if ( is_singular() && has_post_thumbnail( $post->ID ) &&
    							( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
    							$image[1] >= $header_image_width ) :
    						// Houston, we have a new header image!
    						echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    					else :
    						// Compatibility with versions of WordPress prior to 3.4.
    						if ( function_exists( 'get_custom_header' ) ) {
    							$header_image_width  = get_custom_header()->width;
    							$header_image_height = get_custom_header()->height;
    						} else {
    							$header_image_width  = HEADER_IMAGE_WIDTH;
    							$header_image_height = HEADER_IMAGE_HEIGHT;
    						}
    						?>
    					<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    				<?php endif; // end check for featured image or standard header ?>
    			</a>
    			<?php endif; // end check for removed header image ?>
    
    			<?php
    				// Has the text been hidden?
    				if ( 'blank' == get_header_textcolor() ) :
    			?>
    				<div class="only-search<?php if ( $header_image ) : ?> with-image<?php endif; ?>">
    				<?php get_search_form(); ?>
    				</div>
    			<?php
    				else :
    			?>
    				<?php get_search_form(); ?>
    			<?php endif; ?>
    
    <div id="untermenu" role="navigation">
    
    <?php /*wp_nav_menu( array( 'theme_location' => 'primary' ) );*/ ?>
    <ul>
    	<?php wp_list_pages('depth=1&sort_column=menu_order&title_li='); ?>
    </ul><br />
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul id="untermenu_untermenu">
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    		</div>		
    
    </header><!-- #branding -->
    
    	<div id="main">

    I’m sorry to ask you that, but I really don’t know what to do. It’s a code from the twenty eleven theme, but I am working on a copy of that.

    Thank you very much,
    Lula

    Zoe

    (@aquickstudy)

    Couldn’t you just use the regular wp_nav_menu menu and put the child page as the top menu item? You can just change the name to the “parent” name once you’ve added it to the menu.

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey Zoe,

    That is a good idea. I could add the same content from the first Child into the Parent, so it looks like it would ‘jump’ to the first Child, but how do I get the Child Button to ‘active’ (the buttons have a different color when they are active) if its not really active? Its the Parent Page who is active though.

    Thanks for your help πŸ™‚

    Zoe

    (@aquickstudy)

    I actually meant in your Menu, add the child page to the menu twice, and then put one instance in the top level of the menu, renaming it to the name of the parent. That way you aren’t duplicating content across your site (which I believe is an SEO no-no).

    You would still run into similar issues with active states, as this way both the parent and child would highlight but you could likely adjust that by overriding the active state on the top level menu item in your CSS.

    Hi, Lula.

    How about your Permalink Setting, did you set to ‘Post name’?

    Thanks,

    Hanafi.

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey Hanafi,

    No, I didn’t change the ‘Post name’ I’m going to try that. Thank you very much for your advices πŸ™‚ Have a nice day.

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey Hanafi,

    I’ve loaded everything up to the server and I’ve changed the permalinks to ‘Post name’ and now I get ‘Internal Server Error’. I tested the website before my permalink change and everything has worked fine. When I change the permalinks back to the default settings, everything works fine again. I don’t know what I have to change now. Something in the php files? Is there any code who declares how the links should work / how the sites ‘talk’ to each other?
    Thanks for your help πŸ™‚

    Thread Starter LulaViolet

    (@lulaviolet)

    Hey fellows

    Thank you for all your advices. I finally have found the solution for this little issue. I wrote the whole menu myself as html and used several header files to highlight the active pages. Its a bit more work but it works.
    I found following code in the internet (http://www.wprecipes.com/how-to-use-multiple-custom-headers-on-a-wordpress-theme) that was really helpfull and I changed it to my needs:

    <?php
    if (is_page('contact')){
    	include(TEMPLATEPATH.'/headercontact.php');
    }
    elseif (is_page('gallery')){
    	include(TEMPLATEPATH.'/headergallery.php');
    }
    else {
    	include(TEMPLATEPATH.'/headerdefault.php');
    }
    ?>
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Turn parent page off as a page’ is closed to new replies.