How to customize the comments template or wp_list_comments()

In single.php file we have function to add comments functionality. Here in this article I will give the code for customize the comments template.

From wordpress 2.7 version we got the functionality of changing or customizing the comments template as per your theme. As we all know in single.php file we called following function to add comments functionality. wordpress comments is very important functionality. Here in this article I will give the code for customize the comment template.

customize the comments template


<?php comments_template(); ?>

This function basically calls the comments.php file and add the data from wordpress database.

If we check the comments.php file. Usually we are having following content in comments.php file

[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

// Do not delete these lines
 if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
 die ('Please do not load this page directly. Thanks!');

 if ( post_password_required() ) { ?>
 <p>This post is password protected. Enter the password to view comments.</p>
 <?php
 return;
 }
?>

<!-- You can start editing here. -->
<div id="comment">
<?php if ( have_comments() ) : ?>
 <h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>

 <div>
<div><?php paginate_comments_links(); ?></div>
 </div>

 <ol>
 <?php wp_list_comments('callback=wordpressapi_comments'); ?>

 </ol>

 <div>
<div><?php paginate_comments_links(); ?></div>
 </div>
 <?php else : // this is displayed if there are no comments so far ?>

 <?php if ('open' == $post->comment_status) : ?>
 <!-- If comments are open, but there are no comments. -->

 <?php else : // comments are closed ?>
 <!-- If comments are closed. -->
 <p>Comments are closed.</p>

 <?php endif; ?>
<?php endif; ?>

<?php if ('open' == $post->comment_status) : ?>

<div id="respond">

<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>

<div>
 <small><?php cancel_comment_reply_link(); ?></small>
</div>

<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
<?php else : ?>

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

<?php if ( $user_ID ) : ?>

<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a></p>

<?php else : ?>

<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>

<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>

<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>

<?php endif; ?>

<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->

<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>

</form>

<?php endif; // If registration required and not logged in ?>
</div>

<?php endif; // if you delete this the sky will fall on your head ?>
</div>

In the comments loop for showing the comments we used the wp_list_comments() function. Use this for customize the comments template.

We can customize this function as per our requirement. We can pass the following parameters to this function. use following for customize the comments template.


[/viral-lock]

For customize the comments template following parameter is important.

callback (string) The name of a custom function to use to display each comment. Defaults to null. Using this will make your custom function get called to display each comment, bypassing all internal WordPress functionality in this respect. Use to customize comments display for extreme changes to the HTML layout. Not recommended.

In my theme I used that in following way. I changed and passed parameter in comments.php file.


<?php wp_list_comments('callback=wordpressapi_comments'); ?>

Then Open the functions.php file put following code in that. This code I am using as per wordpress api.


function wordpressapi_comments($comment, $args, $depth) {
 $GLOBALS['comment'] = $comment; ?>
 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
 <div id="comment-<?php comment_ID(); ?>">
 <div>
 <?php echo get_avatar($comment,$size='32',$default='<path_to_url>' ); ?>
 <?php $user_name_str = substr(get_comment_author(),0, 20); ?>
 <?php printf(__('<cite><b>%s</b></cite> <span>says:</span>'), $user_name_str) ?>
 </div>
 <?php if ($comment->comment_approved == '0') : ?>
 <em><?php _e('Your comment is awaiting moderation.') ?></em>
 <br />
 <?php endif; ?>

 <div><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),&nbsp; get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp; ','') ?></div>

 <?php comment_text() ?>

 <div>
 <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
 </div>
 </div>
<?php
 }

Many times some people add the full URL of website in the name parameter. That time showing author name of comment writer is looks so ugly. So I used following trick in this function. Using this line of code we can show only 20 characters of author.


<?php $user_name_str = substr(get_comment_author(),0, 20); ?>
 <?php printf(__('<cite><b>%s</b></cite> <span>says:</span>'), $user_name_str) ?>

I changed the this function as per my choose. You can customize this function as per your theme requirement.

customize the comments template
customize the comments template

If you found any issue in this article “customize the comments template” about this. please write comments.

 

wordpress migration to new hosting service or domain

how to do wordpress migration to new hosting service – This question always came to web developers. After searching on Internet I really did not found satisfied answer for this question. Using our steps wordpress migration to new hosting service or domain made easy

wordpress migration to new hosting service or domain

Earlier I did wordpress migration to new hosting service or new domain so many times. It was like 5 minutes job for any web developer. Don’t be afraid about wordpress migration at all.

Many people suggest to use wordpress utility which import and export xml. This is given by wordpress itself. But I strongly say don’t use that tool. that is not really full proof.

Just follow my steps to do wordpress migration to new hosting or domain.

1. First take backup of file system of your wordpress website using FTP credential.

2. Open wp-config.php file and change database name(what you want)

3. wp_options -Table name
option_name column – change(siteurl and home)

4. wp_blogs- Table name
domain column – change to your domain name

5. wp_site- Table name
domain column – change to your domain name

6. wp_usermeta
meta_key column – change(source_domain)

Most important part of migration. Fixing the image path of wordpress website

7. Just run following query using phpmyadmin or command prompt and any sql editor.

UPDATE wp_posts SET post_content = REPLACE(post_content, ’NEW_DOMAIN.com’, ‘OLD_DOMAIN.com’);

For changing the mysql queries you can use the following URL:

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

Follow above steps and your are done with migration.

wordpress migration to new hosting service or domain
wordpress migration to new hosting, question always came to web developers. Using our steps wordpress migration to new hosting service or domain made easy

That sit!

fetch wordpress posts which starting with specific word or alphabet

If you want to fetch wordpress posts which is starts with specific word or alphabet. That is really easy to achieve in wordpress.

Article for fetch wordpress posts which starting with specific word.

Just follow my steps:

Open your functions.php file from your wordpress theme folder.


add_action( 'posts_where', 'starting_word' );
function starting_word( $sql ){
 global $wpdb;
 $starting_word = get_query_var( 'starting_word' );

 if( $startswith ){
 $sql .= $wpdb->prepare( " AND $wpdb->posts.post_title LIKE %s ", $starting_word.'%' );
 }

 return $sql;
}

Open your index.php file or any file where you want show the wordpress posts which is starting with specific word or alphabet.

Use following code in that file.


<?php  query_posts('paged='.$paged.'&starting_word=wordpressapi&category_name=Your Category&posts_per_page=10'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>

<br />
<?php the_content(); ?>
<?php endwhile; ?>

fetch wordpress posts which starting with specific word
fetch wordpress posts which starting with specific word

WordPress vs Joomla vs Drupal, Which is more popular and user friendly

Which CMS is most popular and most user-friendly in the world. WordPress vs Joomla vs Drupal all are best cms. you need to decide what type of site you want.  This is most common question among the developers and clients.

So many times this question is questioned the answered But still I am going answer this question with my opinions.

WordPress vs Joomla vs Drupal

Biggest growth of jobs is WordPress. I am wordpress developer and  I can feel this trend today.
We can this graph that displays the growth of wordpress. Seeing this graph We can say that in 2009 and 2010 wordpress is really rocking.

Wordpress vs Joomla vs Drupal
WordPress vs Joomla vs Drupal

I worked on all the  cms like wordpress, drupal, joomla and many more. But in this year I worked on wordpress for quite some extra time.

When we choose CMS we consider following points.

1. Which CMS will provide you Best Seo options

Ans: When we see and check the all CMS then I can easily say that wordpress has ability to provide you best seo option. After that I will must say Drupal is best option to go with. This will also provide you best seo option.

2. Which CMS is easy to make custom theme from custom design PSD

Ans: I can say with wordpress and drupal both creating a theme is very easy. any web developer who have very basic knowledge of PHP they can develop custom theme very easily.

3. Which CMS is easy  for developer to make custom plugins, modules and components easily

Ans: If you started learning API’s of both the CMS. All are good and easy and all provided good amount of help on internet. But I can rate myself as follows:

a. WordPress

b. Drupal

c. Joomla

Anyways that is depending on your knowledge and understanding. All you need to spend some time to understand the API’s of all CMS.

4. Which CMS admin is most user-friendly and easy to use for non-technical people

Ans: For this point I must say wordpress is the best tool. Drupal has admin panel but little complex to understand and same with joomla.

5. Which CMS is most good for  E-commerce site, Blog, Small site, News sites and company website.

Ans:  I recommend again wordpress here. you can set up wordpress very easily and quickly with minium effort. For big websites like magazine and news sites wordpress is the great tool.

Next point is,  for ecommerce and blogging wordpress is the great tool. If you are aware with wordpress then go with drupal.

Conclusion:  If you want to develop very complex website with multiple features like ad management, forums, client support, video gallery, media gallery then go with Drupal.

So many very big websites are built-in Drupal and WordPress. Choosing the CMS is all depending on your client requirement.

How to use Seo Meta Tags wordpress plugin

we created Seo Meta Tags wordpress plugin. We really happy to announce this news. This is our fourth wordpress plugin by our team which helpful for seo.

How to install SEO meta Tags?

Follow the usual routine;

  1. Open WP admin – Plugins – Add New
  2. Enter “Seo Meta Tags” under search and hit Enter
  3. Plugin will show up as the first on the list, click “Install Now”

Or if needed, upload manually. Follow the steps below to install the plugin.

  1. Upload the seo-meta-tags directory to the /wp-content/plugins/directory
  2. Activate the plugin through the ‘Plugins’ menu in wp
  3. Go to “Seo Meta Tags” option to configure the button

Launched the Seo Meta Tags wordpress plugin

Seo Meta Tags

Using this plugin you will get following features:

We ensure you that Seo Meta Tags plugin will increase your website SEO with two week so drastically.

You can enter your meta keywords and description for your homepage.
This plugin will add different Meta description for each individual post as your excerpt of your post.
This will help your blog to rank better in google. You can easily increase your blog traffic using this plugin.

Using SEO meta tags you can create sitemap for google, yahoo, bing, yandex. It has facility to add  Google, Bing Verify ownership with wordpress website.

This plugin is really helpful to SEO. Search engine will read meta description for each page.
Using this plugin your blog will have different meta description and relative meta description as per your single post.
That is really helpful to your blog.

Here you can see the screen shot of Seo Meta Tags Admin panel:

How to use Seo Meta Tags wordpress plugin
How to use Seo Meta Tags wordpress plugin

You can download Seo Meta Tags from following URL:

Add Webmaster Tool Information.

Official URL of Seo Meta Tags wordpress plugin:

http://wordpress.org/extend/plugins/seo-meta-tags/

How to find wordpress posts by category name

You can fetch the wordpress posts by category name. We have given simple code snippet for find wordpress posts by category name.  Many developer want to do this. I will show how easily achieve this.
You can control the per page post showing and pagination also. You can use following code in any of your page.

How to find wordpress posts by category name

Use following code :

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php  query_posts('paged='.$paged.'&category_name=Your Category&posts_per_page=10'); ?>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php while ($my_query->have_posts()) : $my_query->the_post(); ?>

php the_permalink() ?>" title="<!--?php the_title(); ?-->">
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php the_title(); ?>

<br />
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php the_content(); ?>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endwhile; ?>

find wordpress posts by category name
find wordpress posts by category name

Best IDE for WordPress, Drupal Plugin and Theme development

Many developer who are experienced in development. But with another CMS development. we look for Best IDE for WordPress, Drupal Plugin and Theme development.  But still that comes to another cms or project development. We are always search for good IDE which are free and open source that is the first requirement.

Best IDE for WordPress, Drupal Plugin and Theme development

Our basic need are as follows in any IDE, the IDE need to support following things:

  • CSS
  • XHTML/HTML
  • JavaScript
  • PHP
  • MySQL

I created a list of IDE which I used daily  to do a development. Here I need to clarify IDE is language specific. I work in PHP, Ruby on Rails, Adobe Air, Flex, Javascript, CSS.

I recommend following IDEs which I really found useful for all the developer who are working in wordpress, joomla, drupal development.

1. eclipse (Compatible  on Windows and Linux)

Best IDEs for WordPress, Joomla, Drupal Plugin and Theme development
Best IDE for WordPress, Drupal

Description: Eclipse is best IDE for all language development. Eclipse IdE is basically Java development but still that provides PHP, ROR and other language support. I like this IDE for java development but I did not recommend for PHP or Ruby on Rails.

2. NetBeans (Compatible  on Windows and Linux)

Best IDEs for WordPress, Joomla, Drupal Plugin and Theme development
Best IDE for WordPress, Drupal

Description: This IDE has also all language support. I specially like this IDE from Ruby on Rails development. I Used this IDE for Ruby on Rails development as well as some times for PHP development. Among the Ruby on Rails developer this IDE is so popular.

3. Komodo (Compatible  on Windows and Linux)

Best IDE for WordPress, Drupal
Best IDE for WordPress, Drupal

Description : This IDE is also support for all languages. This IDE is really good support for PHP. I really love this IDE for PHP development. Simple and fast and still nice features about PHP. This IDE is really popular among the PHP developers.

4. Aptana (Compatible  on Windows and Linux)

Best IDE for WordPress, Drupal
Best IDE for WordPress, Drupal

Description : This IDE is mainly made for Ruby on Rails development. This is also popular among Ruby developers. This IDE has features like eclipse. I like this IDE for Adobe Air and flex development.  This IDE has also PHP support.

5. EditPlus (Compatible  on Windows)

Best IDE for WordPress, Drupal
Best IDE for WordPress, Drupal

Description: This IDE is plain simple text editor. Shows you simple color highlight features. I specially recommend this IDE for PHP development and new PHP developer always start with this IDE so they will get filmier with PHP functions and methods because this IDE is does not provide any help. I love the use this IDE in daily use for any language development.

If you want to add any more IDEs. You can comments on this article.

how can we execute custom queries on wordpress

We can use the custom queries in wordpress. Using the custom queries we can fetch the wordpress table data as per our custom requirement.

how can we execute custom queries on wordpress

We you create your table then you can fetch values from that table using following command.

$ourdata = $wpdb->( "SELECT id, name FROM yourtable" );

If you want to create the table in wordpress then use following article.

https://purabtech.in/create-add-tables-wordpress-theme/

More example about executing the own custom quries.

$wpdb->query("
	DELETE FROM $wpdb->postmeta WHERE post_id = '123'
	AND meta_key = 'google'");

another example about adding the data into table which is from wordpress:

$table_name = "your_table";
 $welcome_name = "Mr. WordPressapi";
  $welcome_text = "Congratulations, you just completed the installation!";

  $insert = "INSERT INTO " . $table_name .
            " (time, name, text) " .
            "VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) . "')";

  $results = $wpdb->query( $insert );

Getting the single value from any table

$user_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users;"));

Get the single row value from wordpress table

$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A);
how can we execute custom queries on wordpress
how can we execute custom queries on wordpress

you can use inner join, outer join and multiple join in wordpress custom queries.

Solved: issue with wordpressMU image or media uploading

Many people is having issues with image uploading with WordPressMU. In this article I will tell you the solution. Solved: issue with wordpressMU image or media uploading.

Solved: issue with wordpressMU image or media uploading
Solved: issue with wordpressMU image or media uploading

Solved: issue with wordpressMU image or media uploading

Single wordpress and wordpressMu has different behaviour.. If you are using apache webserver then there is no issue but if you are using than there is issue with image mapping. specially with nginx web server.
You need to write the rewrite rule for image. Also you need to check about folder permission in your “blogs.dir” directory. change folder permission to 777.
For single wordpress there is uploads folder is present but for wordpressMu there is no uploads folder present in directory. You should look for blogs.dir folder which is present in wordpressMu/wp-content folder.

For solve the issue add the following lines in your apache configuration(httpd.conf) file. If this file is not present then add following lines in your .htaccess file.

RewriteEngine On
RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

&lt;IfModule mod_security.c&gt;
&lt;Files async-upload.php&gt;
SecFilterEngine Off
SecFilterScanPOST Off
&lt;/Files&gt;
&lt;/IfModule&gt;

One another issue.
You should check the “Upload File Types” settings going here.
http://yoursite/wp-admin/wpmu-options.php

Check the “Max upload file size” and also check the “Blog upload space”

For Nginx you will find the configuration code from https://purabtech.in/image-upload-issue-in-wordpressmu-with-nginx/

If you have still facing issue with image uploading in wordpressMU. Feel free to write to me or write a comment.

How to create photo gallery in wordpress

Creating a photo gallery is very good idea in any websites because photos say more than text.

So many people create very nice photo galleries in wordpress. Still some people does know how to create a photo gallery using wordpress website.

How to create photo gallery in wordpress

In this article I will give you idea about how to create the photo gallery.

1. NextGEN Gallery

Download

2. Page Flip Image Gallery

Download

3. Image Gallery Reloaded

Download

4. Random image gallery with light box

How to create photo gallery in wordpress

Download