Skip to content

Commit 3ac49ea

Browse files
dynamic footer links.
1 parent 6b092a8 commit 3ac49ea

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

footer.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
<li><a href="/copyright.php">Copyright &copy; <?php echo get_bloginfo('name'); ?></a></li>
77
</ul>
88
<ul class="footmenu">
9-
<li><a href="/my.php">My PHP.net</a></li>
10-
<li><a href="/contact.php">Contact</a></li>
11-
<li><a href="/sites.php">Other PHP.net sites</a></li>
12-
<li><a href="/mirrors.php">Mirror sites</a></li>
13-
<li><a href="/privacy.php">Privacy policy</a></li>
9+
<?php
10+
$menu_items = get_footer_links();
11+
if($menu_items):
12+
foreach($menu_items as $menu_item): if($menu_item->menu_item_parent != 0) continue; ?>
13+
<li class="parent "><a href="<?php echo $menu_item->url; ?>" class="menu-link"><?php echo $menu_item->title; ?></a></li>
14+
<?php endforeach;?>
15+
<?php endif; ?>
1416
</ul>
1517
</div>
1618
</footer>

functions.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
add_theme_support( 'post-thumbnails' );
33
add_action('admin_head', 'php_admin_head');
4-
add_action( 'init', 'phpmanual_header_menu' );
4+
add_action( 'init', 'register_phptr_menus' );
55
add_action("admin_menu", "setup_phpmanual_menu");
66
add_action( 'add_meta_boxes', 'documentation_add_custom_box' );
77

@@ -33,7 +33,7 @@ function my_custom_post_documentation() {
3333
);
3434
register_post_type( 'documentation', $args );
3535
}
36-
36+
3737
add_action( 'init', 'my_custom_post_documentation' );
3838

3939

@@ -94,9 +94,10 @@ function myplugin_inner_custom_box( $post ) {
9494

9595

9696

97-
function phpmanual_header_menu()
97+
function register_phptr_menus()
9898
{
9999
register_nav_menu( 'header_menu', 'Header Menu' );
100+
register_nav_menu( 'footer_links', 'Footer Links' );
100101
}
101102

102103
function php_admin_head()
@@ -132,6 +133,30 @@ function get_header_menu_items()
132133
?>
133134
<div class="error-message">"Header Menu" does not contain a navigation menu. Please <a href="<?php echo get_admin_url()?>nav-menus.php">build</a> and <a href="<?php echo get_admin_url()?>customize.php">select</a></div>
134135
<?php
136+
}
137+
138+
139+
function get_footer_links()
140+
{
141+
$locations = get_registered_nav_menus();
142+
$menus = wp_get_nav_menus();
143+
$menu_locations = get_nav_menu_locations();
144+
145+
$location_id = 'footer_links';
146+
147+
if (isset($menu_locations[ $location_id ]))
148+
{
149+
foreach ($menus as $menu)
150+
{
151+
if ($menu->term_id == $menu_locations[ $location_id ])
152+
{
153+
return wp_get_nav_menu_items($menu);
154+
}
155+
}
156+
}
157+
?>
158+
<div class="error-message">"Footer Links" does not contain a navigation menu. Please <a href="<?php echo get_admin_url()?>nav-menus.php">build</a> and <a href="<?php echo get_admin_url()?>customize.php">select</a></div>
159+
<?php
135160
}
136161

137162
function phpmanual_settings()

0 commit comments

Comments
 (0)