Created
September 26, 2012 04:12
-
-
Save minhman/3785981 to your computer and use it in GitHub Desktop.
function for wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include 'lang.php'; | |
| include 'meta-box.php'; | |
| add_theme_support('menus'); | |
| add_theme_support('post-thumbnails'); | |
| // add_image_size( 'full', 700, 500, false ); | |
| function get_featured_img($post_id){ | |
| $img_id = get_post_thumbnail_id($post_id); | |
| $images=wp_get_attachment_image_src( $img_id, false, false ); | |
| return $images[0]; | |
| } | |
| function thumb_img($post_id,$h,$w,$q,$alt){ | |
| echo '<img align="middle" src="'; | |
| echo bloginfo('template_url'); | |
| echo '/timthumb.php?src='.get_featured_img($post_id).'&h='.$h.'&w='.$w.'&q='.$q.'" alt="'.$alt.'" />'; | |
| } | |
| function thumb_img_bg($post_id,$h,$w,$q){ | |
| echo bloginfo('template_url').'/timthumb.php?src='.get_featured_img($post_id).'&h='.$h.'&w='.$w.'&q='.$q.''; | |
| } | |
| function getCurrentCatID(){ | |
| global $wp_query; | |
| if(is_category() || is_single()){ | |
| $cat_ID = get_query_var('cat'); | |
| } | |
| return $cat_ID; | |
| } | |
| function my_search_form( $form ) { | |
| $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" > | |
| <div><label class="screen-reader-text" for="s"></label> | |
| <input type="text" value="' . get_search_query() . '" name="s" id="s" /> | |
| <input type="submit" id="searchsubmit" value="'. esc_attr__('Tìm kiếm') .'" /> | |
| </div> | |
| </form>'; | |
| return $form; | |
| } | |
| add_filter( 'get_search_form', 'my_search_form' ); | |
| function activeLang(){ | |
| $languages = icl_get_languages('skip_missing=1'); | |
| foreach (array_keys($languages) as $key) { | |
| if ($languages[$key]['active']==1) { | |
| return $languages[$key]['language_code']; | |
| } | |
| } | |
| } | |
| function changeLang($vietnamese,$english){ | |
| $languages = activeLang(); | |
| if ($languages == 'vi') { | |
| echo $vietnamese; | |
| }else{ | |
| echo $english; | |
| } | |
| } | |
| function new_excerpt_length($length) { | |
| return 25; | |
| } | |
| add_filter('excerpt_length', 'new_excerpt_length'); | |
| function limit_words($string, $word_limit) | |
| { | |
| $words = explode(' ', $string, ($word_limit + 1)); | |
| if(count($words) > $word_limit) | |
| array_pop($words); | |
| return implode(' ', $words); | |
| } | |
| function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') { | |
| $header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n"; | |
| mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header); | |
| } | |
| // | |
| add_action( 'wp_ajax_nopriv_sendMail', 'ajaxsendMail' ); | |
| add_action('wp_ajax_sendMail', 'ajaxsendMail'); | |
| function ajaxsendMail(){ | |
| $name = $_POST['name']; | |
| $email = $_POST['email']; | |
| $web = $_POST['web']; | |
| $mess = $_POST['mess']; | |
| if (mail_utf8('[email protected]','Có email từ website: noithat4d.com.vn',$mess,$header)) { | |
| echo "Email sended sussesfull"; | |
| }else{ | |
| echo "Server got problem"; | |
| } | |
| die(); | |
| } | |
| function commentCount(){ | |
| comments_number('No comments', 'One comment', '% comments'); | |
| } | |
| function my_replylink($c='',$post=null) { | |
| global $comment; | |
| // bypass | |
| if (!comments_open() || $comment->comment_type == "trackback" || $comment->comment_type == "pingback") return $c; | |
| // patch | |
| $id = $comment->comment_ID; | |
| $o = '<a class="button reply" id="'.$id.'" href="'.get_permalink().'?replytocom='.$id.'#respond"><span>Replay <img src="/images/repl.png"></span></a>'; | |
| return $o; | |
| } | |
| add_filter('comment_reply_link', 'my_replylink'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment