912WP Menus – Theme Setup & Menu as Array

functions.php function register_theme_menu() { register_nav_menu('my-menu', 'My Menu'); } add_action( 'init', 'register_theme_menu' );

Menu Location $l = get_nav_menu_locations(); $m = wp_get_nav_menu_items($l['my-menu']); foreach($m as $i) { // custom HTML echo $i->url; echo $i->title; }

894How to get Parent ID from a Post Page

if ($wp_query->is_posts_page) { $id = $wp_query->queried_object->ID; }

869Pagination in Custom Queries need $paged

...$nr // number of posts

$args = array( 'posts_per_page' => $nr ? $nr : get_option('posts_per_page'), 'paged' => get_query_var('paged', 1), 'post_type' => 'post', ... );

$wp_query = new WP_Query($args);

while ($wp_query->have_posts()) : $wp_query->the_post(); // display endwhile;

// getPagination()

868Removing Categories on save_post

function onSavePosts($post_id) {

if (wp_is_post_revision($post_id)) return;

// Remove Post Categories, set post categories to empty array wp_set_post_terms($post_id, array(), 'category'); } add_action('save_post', 'onSavePosts');

853PHP define(): single or double quotes?

I recently came across the following situation. A new server, a client-defined database, a database name like this: 'my-database'. Checking if the DB exists in PhpMyAdmin, everything checks out.

Putting all the details in wp-config.php should also work, right?

define('DB_NAME', 'my-database');

Hmmm. No, not quite. Error establishing a database connection

Could it really be, that the dash in 'my-database' messes up the DB_NAME? Apparently yes.

define('DB_NAME', "my-database");

Ok, problem solved. As for why, that's still an open question.

832WordPress, wp_enqueue_script & Order-of-Loading

The Wordpress way of loading Javascript files is through wp_enqueue_script. This ensures that no scripts are loaded twice, and it allows for a mechanism to specify dependencies.

I had the following situation:

A plug-in was loading a JS file with wp_enqueue_script, something like this:

function addMyPluginScript() {
    wp_register_script('my-js', plugins_url('/my.js', __FILE__, array('jquery'), '1.0', false) );
    wp_enqueue_script('my-js');            
}    

add_action('wp_enqueue_scripts', 'addMyPluginScript');

In my theme's functions.php I had the following:

function load_scripts() {                           
    wp_enqueue_script('jquery');
    // ... other scripts
}    
add_action('wp_enqueue_scripts', 'load_scripts');

But although I specified the dependency of 'jquery' in the plug-in's code, the plug-in's JS got loaded BEFORE the theme's jQuery. Hmmm...

The solution was a closer look at the add_action function. Usually it is called with 2 parameters, the hook name and the callback function. But there's also a third, optional parameter: priority. It defaults to 10, and Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

The fix for out problem: Load the functions scripts before anything else:

function load_scripts() {                           
    wp_enqueue_script('jquery');
    // ... other scripts
}    
add_action('wp_enqueue_scripts', 'load_scripts', 1);    // 1 is smaller than the default 10...

764WordPress and Numbers as Page Slugs

If your are using Wordpress you might have run into the following situation. Let's say the main usage of this particular Wordpress installation is not so much blogging (articles), but as light-weight CMS (pages). Wordpress' Page and Subpage system works quite well in this respect, but I am no happy with one thing: Numbers as Page Slugs.

While it's possible to create a new page, name it with a number "2012", the page slug automatically turns to 2012-2. Manually editing the page slug back to "2012" and publishing it should solve that. Unfortunately not. Back to "2012-2".

In most cases, when the page slug is not a number, the presence of a "-2" and the end of the slug suggests, that the page already exists in the database. Make sure it's not in the Trash, empty the trash, if it is.

trembl.org/2012/

It does not seem to be a huge problem, because even when the page slug is "2012-2" and you ask for a page named trembl.org/2012/, Wordpress will happily forward (redirect?) you to trembl.org/2012-2/. So... Working: Yes? Nice solution: No!.

No other choice than to have a look at the MySQL itself. If you are not comfortable doing it on the CL, have a look at phpMyAdmin. Actually, if you are not comfortable editing MySQL, don't do it at all. Messing up the MySQL will mess up you Wordpress installation! And I assume you have a recent backup.

So, with that out of the way, open your Wordpress MySQL DB in phpMyAdmin. The wp_posts table holds all your posts, pages, as well as all the revisions to them. Look for the one you want to edit, in this case "2012-2". Open the entry for editing (the small crayon on the left). You'll want to edit "post_name". Change it to whatever you live ("2012"), save (it's called "Go") and you're done.

Wordpress Version: 3.1.3

233Modifying Quicktags in WordPress

Open:

/wp-includes/js/quicktags.js

Change/Add/Delete tags to your likening.

100jQuery & WordPress

http://wordpress.org/support/topic/226935

The Prototype library was added to WordPress first, so the '$' is set aside for all Prototype functionality. WordPress makes the coder use 'jQuery' in place of '$'. Therefore the first few lines of code should appear as: