Skip to content

Asher Bond

What do you expect?

Archive

Category: wordpress
  1. 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.
  2. 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).

  1. If you are not using Wordpress Mu, you can simply select from wp_term_relationships and wp_posts
  2. 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.

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.

If you have addthis.com and you aren’t satisfied with the plain share button that’s available for Wordpress, you can use this code to change it to the fully functional dropdown share menu. Just add this code to the end of your blog posts. You will most likely want to add it to the archive.php, index.php, and single.php files in your theme directory ( /path/to/wordpress/site/wp-content/themes/sometheme/single.php etc.)

I just made one php file called addthis_button.php that had this code in it:

<?php
// change this to your addthis user name
$addthis_user=’asherbond’;
?>

<!– AddThis Button BEGIN –>
<script type=”text/javascript”>addthis_pub = ‘<?php print $addthis_user; ?>’;</script>
<a href=”http://www.addthis.com/bookmark.php?pub=<?php print $addthis_user; ?>&url=”<?php print get_permalink(); ?>”&title=”<?php print get_the_title($id); ?>”\”" onmouseover=”return addthis_open(this, ”, ‘<?php print get_permalink(); ?>’, ‘<?php print get_the_title($id); ?>’)” onmouseout=”addthis_close()” onclick=”return addthis_sendto()”><img src=”http://s9.addthis.com/button1-share.gif” width=”125″ height=”16″ border=”0″ alt=”" /></a><script type=”text/javascript” src=”http://s7.addthis.com/js/152/addthis_widget.js”></script>
<!– AddThis Button END –>

Then I added the code to include it in each of these files: single.php, index.php, and archive.php:

<?php include(‘addthis_button.php’); ?>

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:

  1. First you must download and install Erik Range’s Syntax Highlighter Plugin.
  2. Download and Unzip the Image Code Generator Plugin from here.
  3. 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!)
  4. 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:

how to use imgcode plugin for wordpress

The plugin will automatically translate code like that into something that looks like this:
Image Code For Your Site: [source:xml] [/source]

If you want to include descriptive information about your image (for search engine optimization) just describe your image using alt= like this.