Thursday, April 18, 2013

Go to to page jQuery Script.

****Script ****
  <script type="text/javascript">
    $(function() {
        $.fn.scrollToTop = function() {
            $(this).hide().removeAttr("href");
            if ($(window).scrollTop() != "0") {
                $(this).fadeIn("slow")
            }
            var scrollDiv = $(this);
            $(window).scroll(function() {
                if ($(window).scrollTop() == "0") {
                    $(scrollDiv).fadeOut("slow")
                } else {
                    $(scrollDiv).fadeIn("slow")
                }
            });
            $(this).click(function() {
                $("html, body").animate({
                    scrollTop: 0
                }, "slow")
            })
        }
    });
    $(function() {
        $("#gototop").scrollToTop();
    });
</script>




**** HTML Code ****
<div class="gototop"><a id="gototop" style="display:none;"><img alt="" src="<?php bloginfo(template_url); ?>/images/topicon.png"></a></div>

****CSS***
#gototop{ position:fixed; bottom:40px; right:75px; cursor:pointer; }

Only show div on homepage/blog index in wordpress/php

The following example can be used in your sidebar to display different content when displaying home page. 

<?phpif ( is_home() ) {
    
// This is a homepage} else {
    
// This is not a homepage}?>


 ------------------------
Also here is an other code.

<?php if(is_home()): ?>

<div>Your div.</div>

<?php endif; ?>
Using above code works fine as long as you are not setting static Page for the Front Page display from here Administration > Settings > Reading.
<?php if(is_front_page()): ?>

<div>Your div.</div>

<?php endif; ?>
But this code will work irrespective of whether the main blog page is showing or you have set a static page to show on home page.

How can i put WordPress Shortcode?

Here is the code for shortcode <?php echo do_shortcode("[contentblock id=1]"); ?>

Wednesday, April 17, 2013

Select the last word in an element & wrap it with a span tag

jQuery(document).ready(function($){
    $('.site-name a').html(function(){   
        // separate the text by spaces
        var text= $(this).text().split(' ');
        // drop the last word and store it in a variable
        var last = text.pop();
        // join the text back and if it has more than 1 word add the span tag
        // to the last word
        return text.join(" ") + (text.length > 0 ? ' <span class="last">'+last+'</span>' : last);
    });
});

WordPress Relative Path to Image/css/js

replace something like:
<img src="images/header.jpg" width="300" height="25" alt="">

with this:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/header.jpg" width="300" height="25" alt="">

Tuesday, April 16, 2013

jQuery Script for Form lenght characters

[contact-form-7 id="34" title="Contact form 1"]
<script type="text/javascript">
jQuery('#wpcf7-f34-p24-o1 form').submit(function() {
var abstract_length = jQuery("#abstract1").val().length + jQuery("#abstract2").val().length + jQuery("#abstract3").val().length + jQuery("#abstract4").val().length + jQuery("#abstract5").val().length + jQuery("#abstract6").val().length + jQuery("#abstract7").val().length;
if(abstract_length >= 2500){
   alert("Maximum Content for Abstract is 2500 Characters.");
   return false;
}
});
</script>