Thursday, August 16, 2012

"This web page has a redirect loop" Problem Resolved


I was getting this error, i tried a lot to resolve it and at last i did it and
i decided to share so that in future if anybody get this error, he can use this
solution as well to resolve this problem.
before this my .htaccess file contain

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
and that is why i am getting this error but after editing my .htaccess file to
this content and my problem resovled.
# END WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
 This may help many of us and may be not all
of us.

Wednesday, August 1, 2012

Limit Post Character in WordPress


Sometime in WordPress we have a requirement that there should be only specific number of Character in our post and there should be read more link which should navigate to some other page. It is very important if you want to show only some lines of data on main page. You can use following code snippet to do this.
<?php
$post_excerpt= limit_post_characters(get_the_content(), get_permalink(),97, "&nbsp;&nbsp;Read more" ); echo $post_excerpt;
?>

Gravity form tabindex problem and short code

If we have single gravity form in our one page then their is not any type of index problem. So if we navigate through our fields then the cursor will go in that sequence in which it should go. But In case when you have multiple Forms on One page then you can face the problem of Tab in gravity form. But it has very simple solution to resolve this problem. You have to use tabindex in gravity form short code it will resolve your problem.

<?php echo do_shortcode('[gravityform id="2" title=false ajax=true tabindex=50]'); ?>

It means that this form Index will start from 50.  How to remove title from gravity form? it is very simple just use title=false as i have used above. If You want to use Ajax in You gravity form just use ajax=true in short code.

Show Custom field in WordPress Post, Custom Field in WordPress

Custom fields are very useful in WordPress and we can attach lot of information as metadata in our Post. Now we may have requirement in which we want to display these Meta data or Custom field in our Post. If you want to display the custom field data in your post or anywhere just use the following code snippet.

      <?php if(get_post_meta($post->ID, 'custom_field_name', true)!=null)
        {
             echo get_post_meta($post->ID, ' custom_field_name ', true);
              }
?>
If you feel any problem in this post just mention it in comment i will try to resolve it.

Show the Post thumbnail or Feature Image in Post WordPress

Post thumbnail or Feature image in WordPress post. In our many posts we use feature images and we also want that these images should also display in our post. To display the feature image or Post Thumbnail use the following code.

                          <?php if ( has_post_thumbnail()) :?>
     <?php the_post_thumbnail(); ?>
 <?php endif; ?>

If you will find any problem just mention it in comment i will try to resolve it.

Limit the Post Title in WordPress


Sometime we have very long post title and we want that only some part of title should display on main page and whole title should only display on single post page. Following code you can use to perform this task.
<?php
            foreach( $myposts as $post ):setup_postdata($post)

                          $post_title=get_the_title();
  $title_length=strlen($post_title);

  $title_sub=substr($post_title,0,29);
if($title_length<30)
the_title();
else
 echo $title_sub."...";
?>
If you will find any problem just mention it in comments, I will try to resolve it.

Simple Form Validation By jQuery, Inline Form validation jQuery


Lot of people want form validation by using jQuery. It is very simple to use jQuery and to perform inline form validation. Just follow the following
some steps to do this task.

 1) Create a form and some of fields
 <form id="buy-house" action="" method="post">
    <ul>
<li> <input type="text" name="First_Name" class="required" placeholder="First Name" /></li>
        <li> <input type="text" name="Last_Name" class="required" placeholder="Last Name" /></li>
        <li> <input type="text" name="Email_Address" class="required email" placeholder="Email Address"  /></li>
        <li> <input type="text" name="Telephone" class="required NumbersOnly" placeholder="Telephone" /></li>
</ul>
<input  type="submit" value="submit"  title="Submit" />
  </form>
  You have noticed that i have used class="required" in fields. basically it is a jquery class that are given in jquery libray that you will
  include in you file as i have mentioned below. you have to place class attribute in that fields which you want to validate otherwise just
  leave a field empty in which you do not want to use this.
 
  2) Now Just download and include the following jQurery libraries.
  <script type="text/javascript" src="jquery.validate.min.js"></script>
           <script type="text/javascript" src="jquery.validate.js"></script>


 3) Now just write the following code to your file head section.
<script>  
$(document).ready(function(){
    $("#buy-house").validate({
});
 });
</script>
now just save the file and run it. Now your form is validating on client side by using jQuery just test it. You have inline validation.

4) If you want to customize your error messages you can use message in you jQuery funtion as i did below.

<script>  
$(document).ready(function(){
    $("#buy-house").validate({
messages: {
      First_Name: { required: "*First Name Required" },
 Last_Name: { required: "*Last Name Required" },
 Email_Address:{ required: "*Email Required" },
 Telephone :{ required: "*Telephone Required" },

   }
      });
 });
</script>

5) Now If you want to style your errors just use .error class it will be included automatically in your jQuery error messages.
<style type="text/css">
.error {
color:red;
    font-weight:bold;
font-style:italic
}
</style>
if You still find any problem just mention it in comments i will try to resolve those.