PurabTech is technical blog for Programmer and Coders
Author: Purab
I am Purab from India, Software development is my profession and teaching is my passion.
Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks.
Purab's Github Repo
Youtube Chanel Video Tutorials
Connect to on LinkedIn
wordpress tutorial, how to make an email address linkable in wordpress. Here we given very simple and short code which you can add in theme.
When ever we insert the URL , email in post we need to put the link manually. WordPress provided the way to automatically make the URL and Email clickable in wordpress post.
how to make an email address clickable in wordpress
how to make an email address clickable in wordpress
You just need to add following code in your wordpress theme’s functions.php file.
wordpress tutorial, how to use wordpress shortcode in text widget. In your shortcode in your wordpress widget section you need to use only following code. From wordpress 2.5 version shortcode method is included in wordpress.
When we use the mobile download we always get the wma files as song file. If you want to convert wma files to mp3 file. For that I written the simple PHP sciprt for converting the wma files through php scirpt.
convert the wma files through php script in linux
Use the following scirpt.
<?php
// Script made for convertion of .wma to .M3 Converter (media conversion) in Linux
//You need the mplayer and lame installted in your linux OS
set_time_limit(0);
ReadDirs('/var/www/html/songs/wmamp3/');
function ReadDirs($dir){
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "Thumb.db") {
$info = pathinfo($file);
if($info['extension']=='wma') {
$mp3_file = str_replace('.wma','',$file);
$cmd = "mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader '".$dir.$file."';lame -m s -V 3 audiodump.wav;mv audiodump.wav.mp3 '".$dir."mp3/".$mp3_file.".mp3';rm -f audiodump.wav";
system($cmd);
}
}
}
closedir($handle);
}
}
?>
Above script will take wma files from folder and convert all files to mp3 files.
Normally running the shell script we will use the following command. If shell script not running then you need to do shell script executable. using following command
execute shell script daily through cron
#./shell_script.sh
If shell script not running then you need to do shell script executable. using following command
#chmod +x shell_script.sh
for running the shell scirpt daily through use the following command
#su
#PASSWORD
#crontab -e
Put following lines in cron file.
* * 1 * * /bin/sh /home/myuser/shellscript/shell_script.sh
People asked me fetching data from wordpress database with simple database query. You can use get_results() method for custom sql query in wp_query function.
Using custom sql query in wp_query function
Is this facility provided by wordpress API. Yes, that is provided by wordpress api. You just need to use the get_results() method. Here I am going to give some example about using the custom sql query in wp_query method.
You need to define the gobal $wpdb variable that important in your code. here is working example for fetching the posts.
global $wpdb;
$querystr = "SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta
WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post'
ORDER BY wp_posts.post_date DESC LIMIT 10";
$pageposts = $wpdb->get_results($querystr, OBJECT);
For fetching the Admin or user information thorough query use following code. following code is useful for fetching the single record or row.
$querystr = "SELECT wp_users.* FROM $wpdb->users
WHERE wp_users.user_email = 'info@domain.com' ";
$userinfo = $wpdb->get_row($querystr);
For detail information you should use the following URL:
So using or choosing the image as featured image for post is another manual work we need to do. Info about. how to set post first image as featured image. We have SQL query for this.
From wordpress 3.0 version wordpress launched the feature called featured image. Many new wordpress themes are compatible with new wordpress version. So using or choosing the image as featured image for post is another manual work we need to do.
Many old wordpress website holder or blogger is having issue with this functionality. What they want is when they create the post they haven’t set the featured image, but they would like the featured image to default to the image that has been included in the post.
Some wordpress always use the first image as featured image but old post was not updated with featured image. They need to do manual work to set the featured image. I also faced same issue.
After doing some R&D I found the solution. If you want to set the your posts first image as featured image then use my following code.
For using the code you need to open your mysql database command prompt or phpmysqladmin program and select your wordpress database and execute the following query in that.
insert into wp_postmeta (meta_value, meta_key, post_id) select DISTINCT(ID), post_type , post_parent from wp_psts where post_type= 'attachment' and post_parent !=0 and post_status='inherit';<br /><br />update wp_postmeta set meta_key = '_thumbnail_id' where meta_key='attachment'
Using above sql query you will be able to set the featured image to your old and new post from post content. If you are having any issues with using this sql then write to me.
How to set post first image as featured image automatically
WordPress is having great setting for SEO purpose but many wordpress blogger did not know about that feature. WordPress has feature called update services. This service will ping when your blog is updated with new post or article.
Use WordPress Update Services for better SEO
This feature is very useful to reach the internet user faster than major search engine. WordPress provide the default http://rpc.pingomatic.com/ service to ping or update the content. Pingomatic is very power server for your wordpress blog.
Use WordPress Update Services for better SEO
For changing the Update services, Login to Admin panel. Go to Settings->Writing->Update Services section from using admin panel . When you see that text box you will only http://rpc.pingomatic.com/ link over there.
My advise to you is when you have good amount content in your blog or website then only use the multiple ping back services.
I used the following services in Update services option.
Above services will submit your site content to major content ping back service. That will boost your site SEO and visitors of your site. After using above ping back urls your site content will be available to users throughout internet faster than google.
I always need to use this method for copy files one remote machine to another machine. there are many tool to do that. filezilla, winscp and many more. But I like command prompt.
rsync copy files from remote server to other server
scp is command is very useful for file transfer on remote machine.
To copy local file on remote machine use following command
#scp FILENAME USERNAME@55.86.59.95:/home/USER/
To copy file from remote machine use following command
#scp USERNAME@55.86.59.95:/home/USER/FILENAME .
or use
#scp USERNAME@55.86.59.95:/home/USER/FILENAME *
To copy file from remote machin using scp command with port
#scp -P54 USERNAME@55.86.59.95:/home/USER/FILENAME .
or use
#scp -P54 USERNAME@55.86.59.95:/home/USER/FILENAME *
Above commands will execute faster than other tools.
rsync copy files from remote server to other server
Sometimes we need the redirection rule for your website. When you want to divert your website traffic to another site.
That is very easy to writing or putting the one site to another site redirection rule through apache.
apache redirect one domain to another site
You need to put entry in your virtual host section or if you are having shared hosting then open your .htaccess file and put following entry in that file
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
You just change newdomain.com to your new website name.