Posts Tagged ‘PHP’

Problem: You need to add a class or id to the the unordered list in wp_page_menu. Maybe to implement some super-slick drop down page menus. But! That <ul> tag is trapped inside of wp_page_menu. What are you going to do?

Solution: Filter wp_page_menu. In the code example below we’ll use preg_replace to find the first—and only the first—

<ul> tag and swap it out for <ul id="nav">. Just drop this code snippet into your theme’s functions.php file and you’re set.
// Add ID and CLASS attributes to the first <ul> occurence in wp_page_menu

function add_menuclass($ulclass) { return preg_replace('/<ul>/', '<ul id="nav">', $ulclass, 1); } add_filter('wp_page_menu','add_menuclass');



WordPress Menu Tricks

Posted: March 3, 2011 in PHP, Wordpress
Tags: ,

In this post I’m going to show you how to take WordPress Menu Editing to the next level. You’re going to learn how to use Primary and Secondary menus in your WordPress theme; Add descriptive sub-title links to your menu items like some popular WordPress themes and sites; Filter the menu of a WordPress theme; Add special CSS classes to wp_page_menu; and finally, how to hand-code your own WordPress menu for the ultimate in control.

Here’s how to make your WordPress menu jump through hoops.

 
Primary and Secondary Menus
This one’s really easy with wp_page_menu. Instead of adding it once to our theme, we’ll add it twice!—but including only select pages each time.

<?php wp_page_menu('exclude=24,27,28&menu_class=menu menu-primary'); ?>
<?php wp_page_menu('include=24,27,28&menu_class=menu menu-secondary'); ?>

Because wp_page_menu generates all the code we’ll need for a menu we simply have to exclude pages from the first menu and include some in the other. With new menu classes ofmenu-primary and menu-secondary we’re all set.

Here’s how to do it with a Thematic Child Theme—or any in any Child Theme where the parent theme is using wp_page_menu. Also easy, but with wp_list_pages so we can avoid any CSS styling problems with multiple drop down menus. Just use this code snippet in your Child Theme functions file.

// Remove the default Thematic Access
function remove_thematic_actions() {
remove_action('thematic_header','thematic_access',9);
}
add_action('init','remove_thematic_actions');
// Recreate the Thematic Access with menu-primary and menu-secondary
function childtheme_page_menu() { ?>
<div id="access">
<div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
<?php wp_page_menu('exclude=24,27,28&menu_class=menu menu-primary'); ?>
<div class="menu menu-secondary">
<ul>
<?php wp_list_pages('title_li=&include=24,27,28'); ?>
</ul>
</div>
</div><!-- #access -->
<?php }
add_action('thematic_header','childtheme_page_menu','9');

(more…)

WordPress can be configured to use different Page Templates for different Pages. There may be any number of reason why you need different page templates and once created you can add or remove items. It allows you to make changes to nearly any aspect of each page (body width, header, font, color, with or without sidebar, etc) without affecting the other pages.

Everytime you want to create a new page there will be an option on the right sidebar which template you will be used when displaying the page.

(more…)

Refreshing DIV using jquery

Posted: November 24, 2010 in HTML, jQuery, PHP
Tags: , ,

There are very simple steps to achieve this:
Step 1:
Copy the following code and paste it in the head section of your webpage.

<script src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
 <script>
var auto_refresh = setInterval(
function()
{
$('#loaddiv').fadeOut('slow').load('reload.php').fadeIn("slow");
}, 20000);
</script>

Here , above the file “reload.php” will be reloaded in every 20000ms ie 20 second . You can change the file which you have to reload and you can also change the reload time as per your requirement.
and secondly , the #loaddiv is the name of DIV which is going to be refreshed.
(more…)

Learn PHP-21 : if… else… else if Statements

Posted: November 20, 2010 in PHP
Tags:

We use the if… else… else if statements to establish conditional logic and evaluate things when needed in our scripts. Sometimes you have to evaluate values to then give the user the correct output on page once the variable value is checked.

if

<?php $current_temperature = 37; // Current South Pole temperature // Then the if statement will evaluate it for us if ($current_temperature > 32) { // Set things to melt if the temp is exceeding 32(freezing) echo "Doom! The icecaps will melt, sea levels will rise."; } // If the temp is still freezing(32), nothing at all will happen in this script ?>
 

The browser is shown like below

Doom! The icecaps will melt, sea levels will rise.

(more…)