The following is (approximately) on line in the sidebar.php file found in the default Word Press theme directory. I’ll use the default theme for this example. I’m also going to assume that you’ve created a navigation group using the NAVT Plugin called sidemenu and it contains a few navigation items.
To add the navt php function you would insert the following code:
<?php
if( function_exists("navt_getlist") ) {
echo "<li><h2>Pages</h2>";
echo "<div>";
navt_getlist("sidemenu");
echo "</div></li>";
}
else {
wp_list_pages('title_li=<h2>Pages</h2>' );
}
?>
Notice that the code begins with the statement if(function_exists(“navt_getlist”)) . This is a golden Rule: Whenever you add a plugin supplied function call to your theme you should always test to see if the plugin’s function exists before executing the function call. This is in case you’ve deactivated the plugin and the function is no longer available. If you’ve deactivated the plugin, chances are very good your theme will break.
If the function exists, the code between the first { (left paren) and } (right paren) will be executed. If you deactivate the plugin and the function no longer exists, the ELSE clause will be executed. In this case, the wp_list_pages will be called instead.
Very interesting article.
I have tried to hack my theme with the following code, but without success… basically i just end up with the site showing a blank page and no page source (suggesting a PHP code error)
Here’s the code:
<?php (if( function_exists(“navt_getlist”) ) {
echo “Pages”;
echo “”;
navt_getlist(“external”);
echo “”:
}
else {
?>
<a href=”/”>Home
<a href=”/”>Home
Would be very grateful if you spotted anything wrong if you could let me know.
Thamnks