Tag: wordpress mu’
How to Select Related Posts (by tags and category relevance) in WordPress
- by Asher Bond
- The first step is to get the post ID of the blog post you are viewing. You can get the id of a post by using $post->ID in WordPress. Let’s pretend it’s 3987.
- You will also need to know the term ids for categories and tags associated with this blog post
Here is some PHP code you can use in wordpress to get the tags of your post ID.
$tags = wp_get_post_tags( $post->ID );
Let’s assume the result is one category (264) and one tag (41).
- If you are not using WordPress Mu, you can simply select from wp_term_relationships and wp_posts
- If you are using WordPress Mu, you will need to specify the tables as wp_MU-BLOG-ID#_term_relationships and wp_MU-BLOG-ID#_posts. Let’s assume we are using WordPress Mu and our blog ID is 1. The tables we are working with are wp_1_term_relationships and wp_1_posts
SELECT p.ID, COUNT(tr.object_id) AS cnt FROM wp_1_term_relationships AS tr, wp_1_posts AS p WHERE tr.object_id = p.id AND tr.term_taxonomy_id IN(264,41) AND p.id!=3987 AND p.post_status='publish' GROUP BY tr.object_id ORDER BY cnt DESC, p.post_date_gmt DESC LIMIT 5;
Notice that we have limited our results to the 5 most relevant posts. It is recommended that you limit this query because it can be a difficult query to process if you are running it on a blog that has thousands of posts. You can change LIMIT 5 to LIMIT 25 or so on blogs that are hosting less than 5,000 posts without seeing much of a difference in performance. On larger, more frequently updated blogs or WordPress MU sites which are hosting a lot of blogs on the same server, it is recommended that you cache the results of this query and only use it once an hour or once every time a blog entry has been updated.
WordPress Mu Tips: How to Import and Export Large Blogs Without The Hassle of Splitting The Files Up
- by Asher Bond
First, log in as a site administrator, then go to the blog you want to export from and choose manage -> export, and save your xml file.
Now log into the blog your importing to as a site administrator and choose manage -> import -> WordPress, and load up the xml file.
You probably get an error message like:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
You could edit your php.ini, but I don’t recommend this because it’s the sledgehammer approach. You can probably use a little more finesse by simply editing your .htaccess file (assuming your web server allows .htaccess to override php.ini).
First try this.. edit:
/path/to/your_wordpress_mu_directory/.htaccess
Add these lines to the top (adjust the values how you need to):
php_value upload_max_filesize 15M php_value post_max_size 15M php_value memory_limit 48M
If you have over ~1000 posts, you may also need to (temporarily) increase the amount of time php scripts are allowed to run before the web server kills the process. Here’s how you can set the maximum execution time of a php script as well as the http request time to (600 seconds) 10 minutes. Thank you Rosalyn Metz.
php_value max_execution_time 600 php_value max_input_time 600
Now try again. If you get the same problem, you will need to edit your php.ini or get your systems administrator / web hosting provider to do it for you. Some web server configurations don’t allow users to override php.ini with .htaccess.
If you are successful, you will probably get a different error:
This file is too big. Files must be less than 1500 Kb in size.
The good news is that this means you have already configured php to allow WordPress to import your large xml file, but you still need to configure WordPress Mu to allow this. When you install WordPress, MU… it creates a record for each blog setting a variable called “fileupload_maxk” to 1500. This is what is limiting you.
Here’s the SQL code you can use to fix it by changing the variable(s) for every mu blog to a higher number (in this case 15000 bytes, but you can change it to a higher or lower number.)
BE SURE TO PUT IN YOUR DATABASE NAME HERE:
UPDATE `__your_wordpress_mu_database_name_here__`.`wp_sitemeta` SET `meta_value` = '15000' WHERE (`wp_sitemeta`.`meta_value` = 1500) AND (`wp_sitemeta`.`meta_key` like "fileupload_maxk");
When you create new blogs, they will still default to 1500. If you want to change this also, you must edit two files:
/path/to/your_wordpress_mu_directory/wp-includes/wpmu-functions.php
and
/path/to/your_wordpress_mu_directory/wp-admin/includes/mu.php
Just change:
get_site_option( 'fileupload_maxk', 1500 )
to
get_site_option( 'fileupload_maxk', 15000 )
(….. or some number of bytes you want instead of 15000.)
That’s it, you should be able to import wordpress blogs as large as you want now.
(Mu Compatible) WordPress Plugins: Image Code Generator
- by Asher Bond
This plugin embeds an image in your blog and offers the code for others to copy so they can also easily post the same image on their site. The code also encloses your image in a hyperlink that links back to your blog post.
Installation:
- First you must download and install Erik Range’s Syntax Highlighter Plugin.
- Download and Unzip the Image Code Generator Plugin from here.
- Normal Installation: Upload the “imgcode” into your wp-content/plugins directory then just activate the plugin from your “Plugins” screen of wp-admin. (You’re Done!)
- ONLY If you are using WordPress Mu and you want to make this plugin available for ALL BLOGS that you are hosting: Upload the contents of “imgcode” (not the actual directory itself) into wp-content/mu-plugins. (You’re done!)
To use the plugin, put code like this in your new blog posts:
![]()
The plugin will automatically translate code like that into something that looks like this:
[imgcode]http://a162.ac-images.myspacecdn.com/images01/24/l_53b0882d564215ad8726072ac7b3f8d9.jpg[/imgcode]
If you want to include descriptive information about your image (for search engine optimization) just describe your image using alt= like this.