Image upload issue in wordpress with nginx

Nginx server is used by wordpress itself. We solved Image upload issue in wordpress with nginx. you can use following code.

Image upload issue in wordpress with nginx

Please Use the following code:


location ~ ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /usr/share/nginx/html/wordpressmu;
rewrite ^/.*(/wp-admin/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-includes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/themes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /wordpress/wp-content/blogs.php?file=$1 last;

expires 10d;
break;
}

NginX Rule for WordPress Mu with Pretty Url

I am using wordpressmu 2.6.5, quite old version. Three month back i moved our site Apache to Nginx. Now these day nobody use wordpress mu. Still article can be used for wordpress multisite.

NginX Rule for WordPress Mu with Pretty Url

Nginx i am using for Rails and WordPressmu application.

I am able to run wordpressmu and Clean Urls(Pretty Url) successfully. I am using Fedora 9 as OS.
“/usr/share/nginx/html/wordpress” – This is my path where i installed WordPressmu

Here is my Nginx code:


server {
listen 80;
server_name localhost.localdomain;
# access_log logs/site.access.log;

location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /usr/share/nginx/html/wordpress;
rewrite ^/.*(/wp-admin/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-includes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/themes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /wp-content/blogs.php?file=$1 last;
expires 10d;
break;
}

location / {
root /usr/share/nginx/html;
index index.php;

rewrite ^.*/.*/files/(.*) /wordpress/wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) /wordpress$1 last;
rewrite ^.+?(/.*\.php)$ /wordpress$1 last;
rewrite ^(.+)$ /wordpress/index.php?q=$1 last;
break;
}

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
include fastcgi_params;

}

location = /50x.html {
root /var/www/nginx-default;
}

}

This code is working fine for me.

wordpress database migration steps

WordPress domain migration is every time required. We given simple wordpress database migration steps. Using following steps you can do domain migration. Whenever you need to push wordpress site local box to production or qa box. you need to change the domain name. I given the simple steps for wordpress database migration. Using following steps you can do the wordpress domain migration.

wordpress database migration steps

First go to wp-config.php file and change database name(what you want)
1. wp_1_options -Table name
option_name column – change(siteurl and home)

2. wp_blogs- Table name
domain column – change

3. wp_site- Table name
domain column – change

4. wp_usermeta
meta_key column – change(source_domain)

use this for
changing all post path and image path
UPDATE wp_1_posts SET post_content = REPLACE(post_content, ‘siwan.wordpress.com’, ‘localhost.localdomain’);

Following Articles are helpful to do the wordpress domain migration.

https://purabtech.in/mysql-queries-wordpress-website-migration/

https://purabtech.in/wordpress-migration-hosting-service-domain/

find replace content in post wordpress

Some times we need to change specific text in wordpress. Using mysql database query or PHPmyadmin interface, you can find replace content in post wordpress. We have given mysql query for replacing the content using database.

find replace content in post wordpress

Use this query for wordpress users


UPDATE wp_1_posts SET post_content = REPLACE(post_content, 'www.test.com', 'www.secondtest.com');

Use this query for wordpress

UPDATE wp_posts SET post_content = REPLACE(post_content, 'www.test.com', 'www.secondtest.com');

How to show or exclude Certain Categories in a Menu – WordPress

If you want show only some categories in wordpress menu than use following command in header.php.

<ul style=”float:left; width:840px;”>
php wp_list_categories(‘orderby=name&include=5,4,8,9,52,65,35’); ?>
ul>

If you want exclude some categories in wordpress menu than use following command in header.php.

840px;”>
php wp_list_categories(‘orderby=name&exclude=5,4,8,9,52,65,35’); ?>
</ul>

Following Options we can use with “wp_list_categories” method.

<?php wp_list_categories( $args ); ?>

args = array(
'show_option_all' => ,
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => ,
'feed_type' => ,
'feed_image' => ,
'exclude' => ,
'exclude_tree' => ,
'include' => ,
'current_category' => 0,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'number' => NULL,
'echo' => 1,
'depth' => 0 ); ?>

 

By default, the usage shows:

  • No link to all categories
  • Sorts the list of Categories by the Category name in ascending order
  • Does not show the last update (last updated post in each Category)
  • Displayed in an unordered list style
  • Does not show the post count
  • Displays only Categories with posts
  • Sets the title attribute to the Category Description
  • Is not restricted to the child_of any Category
  • No feed or feed image used
  • Does not exclude any Category and includes all Categories
  • Displays the active Category with the CSS Class-Suffix ‘ current-cat’
  • Shows the Categories in hierarchical indented fashion
  • Display Category as the heading over the list
  • No SQL LIMIT is imposed (‘number’ => 0 is not shown above)
  • Displays (echos) the categories
  • No limit to depth
  • All categories.

Show Random Posts on page with WordPress

If you want to show random posts each time a client visits. There are many wordpress plugins which will give similar functionality. We have simple code for showing random posts which you need add in your wordpress theme.

Show Random Posts on page with WordPress

You need to create random.php page in your template.  In that page just copy paste the following code:


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1>php the_permalink() ?>"><!--?php the_title(); ?--></h1>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php the_content(); ?>

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endwhile;
endif; ?>

Than create page through wordpress admin panel and select the random page template.

random-wordpress-posts
Show Random Posts on page with WordPress

How to add flash intro in sites and flash with wordpress

If want to ingrate flex or flash with wordpress. Using following steps and code you can add the flash player or flex in your wordpress theme.

 

Many wp developer are looking for wordpress flash header, wordpress flash gallery, wordpress flash player, wordpress flash intro. They want to integrate flex or flash with wordpress. Using following steps and code you can add the flash player or flex in your wordpress theme.

flash with wordpress

 

Follow my steps to create flash intro in wordpress sites.

1. Create file named intro.php and just copy paste following code:

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

<?php

/*

Template Name: intro

*/

if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;

?>

[/viral-lock]

2. Upload intro.php file in your active theme folder.

3. Login to wordpress admin area. Click on Pages- >Add new button

4. Page title shoule be “intro” and use html mode and copy paste the your flash intro code in that page.

flash with wordpress
flash with wordpress

5. In attribute section you will find the Template option. Choose the intro option and publish the page.

flash with wordpress
How to add the flash intro in wordpress sites, flash with wordpress

 

6. Go to Setting->Reading tab and Choose the Static page check box and select the “intro” option for “Front page” and click on save changes button. That sit

Here is some useful articles link from wordpress. If you want to show pdf in post on wordpress  and  add feedburner subscribe popup to wordpress. There all types of wordpress tutorial can be found in this site.

 

how to use conditional tags in wordpress

In this tutorial we are going to show you, how to use conditional tags in wordpress. We given code sample for wordpress theme. How to check page is subpage or parent page.

We got this particular requirement of wordpress menus. For that we need many times parent page menu and sub pages as submenu.

how to use conditional tags in wordpress

Using following code we can able to find the parent page and sub pages from wordpress themes. Following code we can put any where in page or code. We can put this code in header.php or index.php or footer.php or anywhere, as per our requirement.


<?php

global $post;&nbsp;&nbsp;&nbsp;&nbsp; // if outside the loop

if ( is_page() && $post->post_parent ) {

// This is a subpage

} else {

// This is not a subpage

}

?>

If you want use or add the is_subpage() method then you need to add the following code in functions.php file.


<?php

function is_subpage() {

global $post;&nbsp;// load details about this page

if ( is_page() && $post->post_parent ) {&nbsp; // test to see if the page has a parent

$parentID = $post->post_parent;&nbsp;// the ID of the parent is this

return $parentID;&nbsp;// return the ID

} else {&nbsp;// there is no parent so...

return false; // ...the answer to the question is false

};

};

?>

how to use of conditional tags in wordpress

The Conditional Tags  are most useful in creating the wordpress themes and plugins. use of conditional tags in wordpress is necessary in custom themes. The Conditional Tags can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches.

how to use of conditional tags in wordpress

Conditional tag will return the TRUE OR FALSE. Based on return value we can set the conditions. Some useful and most important conditional tags as follows:

is_home()

When the main blog page is being displayed.

is_front_page()

When it is the front of the site displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed

is_admin()

When the Dashboard or the administration panels are being displayed.

is_single()

When any single Post page is being displayed.

is_single('17')

When Post 17 is being displayed as a single Post.

is_single('Irish Stew')

When the Post with Title “Irish Stew” is being displayed as a single Post.

is_single('beef-stew')

When the Post with Post Slug “beef-stew” is being displayed as a single Post.

is_single(array(17,'beef-stew','Irish Stew'))

Returns true when the single post being displayed is either post ID 17, or the post_name is “beef-stew”, or the post_title is “Irish Stew”.

is_page()

When any Page is being displayed.

is_page('42')

When Page 42 (ID) is being displayed.

is_page('About Me And Joe')

When the Page with a post_title of “About Me And Joe” is being displayed.

is_page('about-me')

When the Page with a post_name (slug) of “about-me” is being displayed.

is_page(array(42,'about-me','About Me And Joe'))

Returns true when the Pages displayed is either post ID 42, or post_name “about-me”, or post_title “About Me And Joe”.

How to remove category word from your WordPress URL

This pretty much old article and trick, shown, How to remove category word from your WordPress URL. Now these days many wordpress plugins aviable which will remove cateogry word from wordpress url.

How to remove category word from your WordPress URL

Open your .htaccess file. This file you will find in your root directory.

Just copy and past following code in that file.

RewriteRule ^category/(.+)$ http://images.purabtech.in/$1 [R=301,L]

Don’t forget to replace the purabtech.in/files/ to your site name.

Have fun!

Refer this Remove category slug wordpress from URL and Remove short words from wordpress permalink URL