Thứ Sáu, 24 tháng 2, 2017

Button Animated Call-to-Action PureCSS

See the Pen animation button#2 by lichinlin (@lichin-lin) on CodePen.



See the Pen Shiny CSS Animation Button by Aundre Kerr (@aundrekerr) on CodePen.



See the Pen Flat & Shiny Button (hover effect) by Nathaniel Watson (@nw) on CodePen.



See the Pen Button Fun by Jack Cuthbert (@JackCuthbert) on CodePen.



See the Pen Wacom button:hover effect by Terence Devine (@tdevine33) on CodePen.



See the Pen Button Concept by Chris Deacy (@chrisdothtml) on CodePen.



See the Pen 3D Paper button effects by Ashley Nolan (@ashleynolan) on CodePen.



See the Pen Transitional Buttons by Vitaliy (@kavendish) on CodePen.



See the Pen Material Button Hover by Michael Truong (@YikesItsMikes) on CodePen.



See the Pen Button with sliding information by Miro Karilahti (@miroot) on CodePen.



See the Pen Buttons by Taeha (@zootia) on CodePen.



See the Pen Button Shine Effect by Dan Mensinger (@dmensinger) on CodePen.



See the Pen Animated CSS3 Buttons by Sazzad (@sazzad) on CodePen.



See the Pen CSS only "Material Design" Animated Buttons by Jon Brennecke (@jonbrennecke) on CodePen.



See the Pen Button Blip by Shaun Crittenden (@shaun) on CodePen.

Hiển thị các bài viết được Sticky trong Wordpress

<?php
$sticky = get_option( 'sticky_posts' );
rsort( $sticky );
$sticky = array_slice( $sticky, 0, 2 );
if (is_numeric($sticky[0])) {
query_posts( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 2 ) );
while ( have_posts() ) : the_post(); ?>

// Gọi hàm hiển thị nội dung

<?php endwhile;
wp_reset_query(); } ?>

Thứ Bảy, 11 tháng 2, 2017

Chèn quảng cáo vào giữa nội dung wordpress



Chèn vào file function.php

<?php
//chèn quảng cáo nội dung giữa
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Code quảng cáo</div>';//bạn có thể thêm code hoặc là ảnh image vào đây
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 5, $content ); // số 5 là chèn sau thẻ </p> thứ 5
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}

Thứ Sáu, 10 tháng 2, 2017

Giới hạn ký tự nội dung cho the_excerpt wordpress

Sử dụng trong file function.php

/**
* Limit the length of 'the_excerpt' in WordPress
*/

function limit_words($string, $word_limit) {
$words = explode(' ', $string);
return implode(' ', array_slice($words, 0, $word_limit));
}




Tiếp theo chèn code dưới đây vào vị trí bạn muốn hiển thị

<?php echo limit_words(get_the_excerpt(), '30'), ' ...'; ?>

Thứ Tư, 8 tháng 2, 2017

Hướng dẫn tạo Widget Wordpress tutsplus.com

Building WordPress widgets is just like building a plugin but it is more simple and straightforward. All you need to do is have a single file in which all the PHP goes and it's easier to code than a plugin which can have more than one file. There are three major functions of a widget which can be broken down into widgetupdate and form.
  • function widget()
  • function update()
  • function form()
The basic outline of our widget is very simple and there are a handful of functions that you'll need to know. The bare bone structure of our widget is something like this:
Before we do all that we'll first load our widget whenever necessary by the function "widget_init". This is an action hook and you can find more about it in the WordPress codex.
Next thing that we'll do is register our widget in WordPress so that it is available under the widgets section.
We will enclose our widget in a class. The name of the class is important! One thing that should be kept in mind is that the name of the class and the name of the function should be the same.
Now we'll pass some setting parameters to this class. For example we can pass this the width and height. We can also give our widget a little description if we want to, which is useful if you are bundling this widget with your commercial theme.
Now that we have completed the basic requirements for our widget, we'll move our attention to the three functions that we talked about earlier which are the important functions or the main building blocks of our widget!
The first function is related with the display of our widget. We'll pass a couple of arguments to our widget function. We'll be passing arguments from the theme, which can be a title and other specific values. Next we are passing the instance variable, which is related with the class of our function.
After that we'll extract the values from the argument because we want the values to be available locally. If you don't know what this local variable is all about, just don't worry about it right now and simply add this step!
Next up we will be setting the title and other values for our widget, which can be edited by the user under the widgets menu. We are also including the special variables like $before_widget$after_widget. These values are handled by the theme.
Next up is the update function. This function will take the user settings and save them. It will just update the settings according to the user's taste.
One thing to note here is that we are stripping the values so that any XHTML can be removed from the text which, in simple words, might affect the working of our widget.
The next step will outline creating the form which will serve as the input box. This will take in the user defined settings and values. The form function can include checkboxes, text input boxes etc.
Before we create these input fields, we'll have to decide what to show when the user doesn't select anything from the widget. To do this we will pass some default values to it like title, description etc.
Now we'll create the input text box. We will enclose these options within the paragraph enclosing tag.
And that's it. You just made yourself a very nice and simple widget which displays the name of the author of the blog. Furthermore it gives the option to the user whether or not to show it publicly to the audience. Save the code in a PHP file and upload it to your theme directory. Call it in your functions.php. After that go to your widgets panel and you will see the newly created widget.