Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a custom route for a WP Mutlisite network.

If you're familiar with WPMS, you know that the db tables for each blog on the network begin with something like {prefix}_2_. Normally, visiting mysite.com/blogname is what takes you to the blog's homepage. What I'd like to do, is have mysite.com/2 (look for numeric URI) route to the homepage of the blog whose db tables begin with {prefix}_2_.

Is this possible?

share|improve this question
    
Why? What problem do want to solve with that? –  toscho Jan 30 '13 at 4:46
    
Just clarifying, the number is the blog/site ID. And the {prefix} is common to Multi or Single Site. –  brasofilo Jan 30 '13 at 4:46
    
That's correct, @brasofilo. Obviously I was brain-dead by the time I posted this question. –  user26750 Jan 31 '13 at 2:05
    
@toscho I wouldn't say it's a problem, I just have several reasons for wanting to do things a little differently. –  user26750 Jan 31 '13 at 2:05
    
26750, you have a cool avatar, what about putting you nick/name in your profile? ;)) ::::::::::::::::::::: You can edit your Question whenever needed (add new info, clarify things, etc). –  brasofilo Jan 31 '13 at 2:13

1 Answer 1

up vote 1 down vote accepted

Maybe you are looking for a URL Rewrite (.htaccess) answer, but a simple solution is giving the site name its ID.

site name as id


Not related, but useful: add a column with the site ID in the Sites screen (/wp-admin/network/sites.php).

Drop the plugin in the mu-plugins folder.

<?php
/**
 * Plugin Name: Multisite - Add Site ID Column
 * Version: 0.1
 * Author: brasofilo 
 */

add_filter( 'wpmu_blogs_columns', 'brsfl_get_id' );
add_action( 'manage_sites_custom_column', 'brsfl_add_columns' , 10, 2 );
add_action( 'manage_blogs_custom_column', 'brsfl_add_columns' , 10, 2 );
add_action( 'admin_head-sites.php', 'brsfl_add_style' );

function brsfl_get_id( $columns ) 
{
    $columns['blog_id'] = __('ID');
    return $columns;
}

function brsfl_add_columns( $column_name, $blog_id ) 
{
    if ( 'blog_id' === $column_name )
    {
        echo $blog_id;
    }
    return $column_name;
}

function brsfl_add_style() 
{
    echo '<style>#blog_id { width:7%; }</style>';
}
share|improve this answer
    
I went with a combination of your suggestion (use ID as site name) and an Apache rewrite: –  user26750 Feb 5 '13 at 4:05
    
.htaccess: RewriteRule ^([0-9]+)/(.*)$ /$2?blog_id=$1 functions.php: add_action( 'parse_request', 'my_rewrite' ); function my_rewrite() { if ( is_numeric($_GET['blog_id']) ) { switch_to_blog($_GET['blog_id']); } } get next blog ID for blog name when creating new blog: ` wp_update_network_counts(); $blogName = get_blog_count() + 1; ` –  user26750 Feb 5 '13 at 4:13
    
The idea is, I'm starting with just blog IDs in the URL for the early stages of my network, and at some point in the future (I have my reasons) I plan to allow site admins to claim a custom URL (site name). @brasofilo sorry, I'm new here (obviously) and I couldn't figure out how to "claim" this question in my "real" account :-/ –  user26750 Feb 5 '13 at 4:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.