Responsive Background-Image inside Div

html { 
background: url(images/bg.jpg)no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;
background-size: cover;}
Advertisements

LESS (stylesheet language)

LESS (Leaner CSS) is a dynamic stylesheet language designed by Alexis Sellier. It is influenced by Sass and has influenced the newer “SCSS” syntax of Sass, which adapted its CSS-like block formatting syntax.

Variables

LESS allows variables to be defined. LESS variables are defined with an at sign(@). Variable assignment is done with a colon (:).

During translation, the values of the variables are inserted into the output CSS document.[4]

@color: #4D926F;

#header {
color: @color;
}
h2 {
color: @color;
}

The code above in LESS would compile to the following CSS code.

#header {
color: #4D926F;
}
h2 {
color: #4D926F;
}

Mixins

Mixins allow embedding all the properties of a class into another class by including the class name as one of its properties, thus behaving as a sort of constant or variable. They can also behave like functions, and take arguments. CSS does not support Mixins. Any repeated code must be repeated in each location. Mixins allow for more efficient and clean code repetitions, as well as easier alteration of code.[4]

.rounded-corners (@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}

#header {
.rounded-corners;
}
#footer {
.rounded-corners(10px);
}

The above code in LESS would compile to the following CSS code:

#header {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#footer {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}

LESS has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.

Swap two variables value without using third variable in php

Bit in Expression1 Bit in Expression2 Result
0 0 0
0 1 1
1 0 1
1 1 0
Example with two variable by XOR: decimal
$a = 5;               // 5 => 00000101
$b = 6;              // 6 => 00000110
$a = $a ^ $b; // 3 => 00000011   Now XOR of 5 and 6 is 3
$b = $a ^ $b; // 5 => 00000101  Now XOR of 6 and 3 is 5
$a = $a ^ $b; // 6 => 00000110  Now XOR of 3 and 5 is 6

echo $a.” “.$b;  // Output will be $a=6; $b=5

Validating Sanitizing and Escaping User Data

$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );

Behinds the scenes, the function does the following:

  • Checks for invalid UTF-8 (uses wp_check_invalid_utf8())
  • Converts single < characters to entity
  • Strips all tags
  • Remove line breaks, tabs and extra white space
  • Strip octets

The sanitize_*() class of helper functions are super nice for us, as they ensure we’re ending up with safe data and require minimal effort on our part:

Use of Referencing in php

There are advantages of using references, for example you don’t have to return anything from the function, nor do you have to look to define them as globally accessible.

EXAMPLE:

function lowercase(&$string){
    $string = strtolower($string);
}

$name = 'SAJU';
lowercase($name);
echo $name; // returns saju

How to Display Any RSS Feed on Your WordPress Blog

<h2><?php _e( ‘Recent news from Some-Other Blog:’, ‘my-text-domain’ ); ?></h2>

<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . ‘/feed.php’ );

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( ‘http://www.wpbeginner.com/feed/&#8217; );

if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly

// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );

// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );

endif;
?>

<ul>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( ‘No items’, ‘my-text-domain’ ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href=”<?php echo esc_url( $item->get_permalink() ); ?>”
title=”<?php printf( __( ‘Posted %s’, ‘my-text-domain’ ), $item->get_date(‘j F Y | g:i a’) ); ?>”>
<?php echo esc_html( $item->get_title() ); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>

 

FOR MORE DETAILS:  Click here…!!!

Check has post next and previous link

<?php
$previous_post = get_adjacent_post(false, '', true);
$next_post = get_adjacent_post(false, '', false);
?>
<ul>
<?php if ($previous_post): // if there are older articles ?>
    <li class="prev">Previous post: <a href="<?php echo make_href_root_relative(get_permalink($previous_post)); ?>"><?php echo get_the_title($previous_post); ?></a></li>
<?php endif; ?>
<?php if ($next_post): // if there are newer articles ?>
    <li class="next">Next post: <a href="<?php echo make_href_root_relative(get_permalink($next_post)); ?>"><?php echo get_the_title($next_post); ?></a></li>
<?php endif; ?>
</ul>

How to Exclude Sticky Posts from the Loop in WordPress

How to take away the Sticky Ability of the Post

When you are displaying most recent posts in a tab, you do not want the sticky posts to stay sticky. If you do not remove the sticky features, the recent posts area would be useless as all of your sticky posts will crowd this area. This is when query_posts feature comes in handy.

To do this you will need to change your loop to something like this:

<?php
query_posts(‘caller_get_posts=1’);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

Completely exclude Sticky posts from the Loop

If you are using Sticky posts in a slider, then sometimes you might want to completely exclude your sticky posts from the loop. All what you have to do is edit your custom loop to match with this:

<?php
query_posts(array(“post__not_in” =>get_option(“sticky_posts”)));
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

This code will not display any sticky posts in the post loop.

Stylish Checkbox with CSS

STYLE:
label {
display: inline;
}
.regular-checkbox {
display: none;
}
.regular-checkbox + label {
background-color: #fafafa;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
padding: 9px;
border-radius: 3px;
display: inline-block;
position: relative;
}
.regular-checkbox + label:active, .regular-checkbox:checked + label:active {
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px 1px 3px rgba(0,0,0,0.1);
}
.regular-checkbox:checked + label {
background-color: #e9ecee;
border: 1px solid #adb8c0;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05), inset 15px 10px -12px rgba(255,255,255,0.1);
color: #99a1a7;
}
.regular-checkbox:checked + label:after {
content: ‘\2714’;
font-size: 14px;
position: absolute;
top: 0px;
left: 3px;
color: #99a1a7;
}
.big-checkbox + label {
padding: 18px;
}
.big-checkbox:checked + label:after {
font-size: 28px;
left: 6px;
}
.tag {
font-family: Arial, sans-serif;
width: 200px;
position: relative;
top: 5px;
font-weight: bold;
text-transform: uppercase;
display: block;
float: left;
}
.regular-checkbox + label {
background-color: #fafafa;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
padding: 9px;
border-radius: 3px;
display: inline-block;
position: relative;
}
HTML

<input type="checkbox" id="checkbox-1-1" class="regular-checkbox"  /><label for="checkbox-1-1"></label>
<input type="checkbox" id="checkbox-1-2" class="regular-checkbox"  /><label for="checkbox-1-2"></label>
<input type="checkbox" id="checkbox-1-3" class="regular-checkbox"  /><label for="checkbox-1-3"></label>
<input type="checkbox" id="checkbox-1-4" class="regular-checkbox"  /><label for="checkbox-1-4"></label>

regular expression syntax in php

Example Description
‘/hello/’ It will match the word hello
‘/^hello/’ It will match hello at the start of a string. Possible matches are hello or helloworld, but not worldhello
‘/hello$/’ It will match hello at the end of a string.
‘/he.o/’ It will match any character between he and o. Possible matches are helo or heyo, but not hello
‘/he?llo/’ It will match either llo or hello
‘/hello+/’ It will match hello on or more time. E.g. hello or hellohello
‘/he*llo/’ Matches llo, hello or hehello, but not hellooo
‘/hello|world/’ It will either match the word hello or world
‘/(A-Z)/’ Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C…
‘/[abc]/’ It will match any single character a, b or c
‘/abc{1}/’ Matches precisely one c character after the characters ab. E.g. matches abc, but not abcc
‘/abc{1,}/’ Matches one or more c character after the characters ab. E.g. matches abc or abcc
‘/abc{2,4}/’ Matches between two and four c character after the characters ab. E.g. matches abcc, abccc or abcccc, but not abc