Trying to create navigation menu in Wordpress theme

Hello everyone,
I am trying to create my own theme in Wordpress. I am trying to create in functions.php the navigation menu for my categories and they are 4 in total. Additionally I want to display a navigative link in the footer as well but it will have three different links. Any help will be huge. Thanks in advance

In my functions.php file I have:

<?php

	function theme_setup(){
		add_theme_support('custom-background');
		add_theme_support('custom-header');
		add_theme_support('post-thumbnails');

		register_nav_menus(array('menu1'=>'Primary Menu','menu2'=>'Secondary Menu'));
	}

		add_action('after_setup_theme','theme_setup');


?>

In my header.php file I have:

<?php ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>

	<?php wp_head(); ?>

</head>
<body>
	<header>
		<img src="<?php header_image(); ?>" alt="">

		<h1><a href="<?php echo bloginfo('wpurl');?>"><?php echo bloginfo( 'name' ); ?></a></h1>

		<?php wp_nav_menu(array('theme_location'=>'menu1'));?>
	</header>
	<main>

And in my footer.php file I have:

<?php  ?>
</main>

<?php wp_footer(); ?>
<?php wp_nav_menu(array('theme_location'=>'menu1'));?>
</body>
</html>

Are you building entirely from scratch or using underscores or a similar starter theme?

Hello @MotiMo,
How are you?
I am creating it from scratch

Hello! I’ve been better but that aside. If you are creating it completely from scratch then I would definitely recommend considering using Underscores, Sage or another starter theme, if not as the base then at least as a guide to help you organize your own theme.

Why are you creating a nav menu from scratch? Use the wordpress menu, follow the process other themes use.

Actually we have been instructed to create right from scratch. Its ok I have figured it out :slight_smile:
Thank You

WHOLLY HELL!!!

Instructed as in via a professor? Just wondering why you would use wordpress and not leverage its abilities. Seems, well it is, stupid.

1 Like

Yes, our professor asked us to create a theme from scratch and create customized nav menus (registering them)

I am going to tell you to forget whatever they teach you when you leave then.

WordPress is simple overall, but it is because everyone follows the same rules and practices. Themes are easy, but making a nav menu in the theme is a horrid practice for a few reasons, primarily of which, when the user switches the theme, they loose access to those pages. Learning this, you should take a theme and see how it works, them modify it so you can learn what it does. Considering the pages are built thru the database, a custom nav that sits outside of that will break the process.

3 Likes

Oh I see. Ok :slight_smile: I will learn the way you have suggested. Yes, I noticed many times u have suggested so far the coding practices suggested by him is bad

Whaaaat!? haha Yes I will echo what Astonecipher says here. This is not really a practical or smart way to learn WP. I would definitely suggest working with a “starter” or base theme as I mentioned above. Those are themes that are made to work as a framework for customization, but they are basically a skeleton of a theme that you can learn from and customize as you like. IMHO it is a better approach to learn from a properly set up and lean theme, than it is to try and learn how to create an entire theme from scratch. Just my 2cents, Good Luck with the class~

1 Like

Thank You :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service