custom field them truong trong wordpress

sau đây mình hướng dẫn các bạn về custom field có sẵn trong wordpress
buoc 1 :


Buoc 2 :


Buoc 3 :


điền tên vào ô số 3  , và điền  giá trị  vd gia tien , thuoc tinh mau sac

va cuoi cung  cau lenh  hien thi ra nhe 
<?php echo get_post_meta($post->ID,'ten ban dat',true)  ?>

các bạn nếu ko làm dc hay bình luận nhé mình sẽ trả lời



chức năng gọi điện

chức năng gọi điện  ,như bài trước bài này mình tiếp tục gửi tới các bạn code gọi đt cho website của nình nhé

code này khi nhỏ hơn 650px thì mới hiển thị ra    thay doan nay  0947499221 thanh sdt cua moi nguoi nhe

style>#callnowbutton {display:none;} @media screen and (max-width:650px){#callnowbutton {display:block; height:80px; position:fixed; width:100%; left:0; bottom:-20px; border-top:2px solid rgba(51,187,51,1); background:url(http://callnowbutton.com/phone/callbutton01.png) center 10px no-repeat #009900; text-decoration:none; box-shadow:0 0 5px #888; -webkit-box-shadow:0 0 5px #888; -moz-box-shadow:0 0 5px #888; z-index:9999;}}</style><a href="tel:0947499221" onclick="_gaq.push(['_trackEvent', 'Contact', 'Call Now Button', 'Phone']);"  id="callnowbutton">&nbsp;</a>


code goi dien khi click vao

code gọi điện ,code goi dien , ngày nay dung smart phone qua quen voi mọi người nên code dùng để gọi điện

Viết số điện thoại ở trong một định dạng thích hợp sẽ tự động chuyển chúng thành liên kết cho người sử dụng điện thoại di động. Tuy nhiên với các điện thoại đời cũ hay cục gạch thì hết cách.
<!--Link này làm việc trên Android và iPhone. -->
<a href="tel://0947499221">0947499221</a> 
<a href="tel://0947499221">Call Me</a>
<!-- Link này sẽ bât Skype trên desktop và notebooks, trên điện thoại nó sẽ hỏi người sử dụng nếu họ muốn bật skype hoặc gọi điện bằng dịch vụ di động của họ -->
<a href="callto://0947499221">0947499221</a>

<!-- Link a number to an image -->
<a title="Call Me" href="callto://0947499221"><img alt="Call Me" src="duong dan anh" /></a>


<a href="skype:echo123">Skype</a>


Bài viết liên quan 2

Bài viết liên quan 2
bai viet lien quan 2 . Mình vừa tìm được cách thứ 2 viết bài viết liên quan
đầu tiên các bạn vào functions.php kiểm tra xem có 2 hàm này ko
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 50, true );
  • Dòng 1: Để bật tính năng thumbnail của bài viết.
  • Dòng 2: Để set width và hight của ảnh thumbnail.
Thật ra đa số có những dòng này 

và code quan trọng nhất đây chúng ta đặt trong singgle . Hoặc chỗ nào bạn thích 
<div>  
    <h3>Related posts</h3>  
    <?php  
        $orig_post = $post;  
        global $post;  
        $tags = wp_get_post_tags($post->ID);  
        if ($tags) {  
        $tag_ids = array();  
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;  
        $args=array(  
        'tag__in' => $tag_ids,  
        'post__not_in' => array($post->ID),  
        'posts_per_page'=>4, // Số bài viết liên quan muốn hiển thị.  
        'caller_get_posts'=>1  
        );  

        $my_query = new wp_query( $args );  

        while( $my_query->have_posts() ) {  
        $my_query->the_post();  
        ?>          
        <div>  
            <a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />  
            <?php the_title(); ?>  
            </a>  
        </div>         
        <? }  
        }  
        $post = $orig_post;  
        wp_reset_query();  
        ?>  
</div>

Bạn thay đổi kích thước ảnh bằng hàm này nhé <?php the_post_thumbnail(array(150,100)); ?>

Bài viết ngẫu nhiên , bài viết xem nhiều nhất

bài viết ngẫu nhiên trong wordpress , bài viết xem nhiều nhất

Các bạn có thể không dùng blugin khi làm cái này cũng được sau đây mình xin giới thiệu 2 code trên như sau . Thấy hay nhớ like cho mình nhé 
<h3>Bài ngẫu nhiên</h3>
    <div class="box">
      <?php
 $rand_posts = get_posts('numberposts=so_bai_hien_thi&orderby=rand');
 foreach( $rand_posts as $post ) :
 ?>
      <li > <a style="font-weight: bold;" href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></li>
      <?php endforeach; ?>
      </li>
</div>


Còn đây là code hiển thị bài viết được xem nhiều nhất :




<h3>Xem nhiều nhất</h3>
<div class="box">
        <?php $popular_number = so_bai_hien_thi; $result = $wpdb->get_results("SELECT comment_count,ID,post_title,post_content FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $popular_number");
            foreach ($result as $post) {
            setup_postdata($post);
            $postid = $post->ID;
            $title = $post->post_title;
            $content = $post->post_content;
            $commentcount = $post->comment_count;
            if ($commentcount != 0) { ?>
            <li>
            <a style="font-weight: bold;" href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
            <?php } } ?>
</div>

Bài viết liên quan wordpress

Bài viết liên quan wordpress
bai viet lien quan wordpress , bài viết liên quan wordpress ,
Sau đây mình cũng trình bày 2 thủ thuật bài viết liên quan mình sưu tầm được của hdit và blog thạch phạm

Shortcode bài viết liên quan

/* Shortcode bai viet lien quan */
function dtrung_rp_shortcode($atts){
  extract(shortcode_atts(array(
/* Số bài viết hiển thị */
    'count' => '5',
    'title' => 'Bài viết liên quan',
    ), $atts));
  global $post;
/* lấy theo category */
  $current_category = get_the_category($post->ID);
  $current_category = $current_category[0]->cat_ID;
  $this_category = '';
  $tag_ids = array();
  $tags = get_the_tags($post->ID);
  if ($tags) {
    foreach($tags as $tag) {
      $tag_ids[] = $tag->term_id;
      }
 } else {
    $this_category = $current_category;
        }
  $args = array(
    'post_type' => get_post_type(),
    'numberposts' => $count,
    'orderby' => 'date',
    'order' => 'DESC',
    'tag__in' => $tag_ids,
    'cat' => $this_cat,
    'exclude' => $post->ID
    );
  $dtrung_rp = get_posts($args);
    if ( empty($dtrung_rp) ) {
      $args['tag__in'] = '';
      $args['cat'] = $current_category;
      $dtrung_rp = get_posts($args);
      }
    if ( empty($dtrung_rp) ) {
      return;
     }
  $post_list = '';
  foreach($dtrung_rp as $re_post) {
    $post_list .= '<li><a href="' . get_permalink($re_post->ID) . '">' . $re_post->post_title . '</a></li>';
    }
    return sprintf('
      <div class="dtrung-related-posts">
        <h3>%s</h3>
        <ul>%s</ul>
      </div>
    ', $title, $post_list );
    }
add_shortcode('dtrung_related_posts', 'dtrung_rp_shortcode');

cách dùng [dtrung_related_posts] nhét vào chỗ cần hiển thị 
Tiếp theo 
// Hàm xác định thẻ </p> đầu tiên
function count_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 );
// Chèn shortcode bài viết liên quan vào sau thẻ </p> đầu tiên
add_filter( 'the_content', 'insert_shortcode_related_posts' ); 
function insert_shortcode_related_posts( $content ) {
   $related_posts= do_shortcode('[dtrung_related_posts]');
   if ( is_single() ) {
      return count_paragraph( $related_posts, 1, $content );
   }
   return $content;
}
Sau đó
<?php echo do_shortcode('[dtrung_related_posts]') ?>
Và tôi thấy cách trên hơi dài nhưng các bạn đấy là  tôi sưu tầm được thôi còn lại chúng ta làm theo cách sau này tôi thấy ngắn hơn
WordPress Related Posts
bạn có thể làm rất nhanh tôi thấy rất hay hãy dùng blugin nếu chúng ta ngại viết code

Code cơ bản của wordpress

Chào các bạn mình xin giới thiệu 1 số code cơ bản của wordpress
Về header
<?php wp_head(); ?> // Khai báo
 <?php get_header();?> // Gọi header


Về footer 
<?php wp_footer(); ?> // Khai báo
<?php get_footer(); ?> // Gọi footer

Lấy đường dẫn
<?php echo get_template_directory_uri() ?> // Lấy đường dẫn thư mục
<?php echo get_site_url(); ?> // Lấy đường dẫn gốc của site
<a href="<?php echo get_site_url(); ?>/?page_id=1"></a> // Đường dẫn page
<?php echo ( get_the_ID() == 1 ) ? 'active':''  ?> // Gọi class active
Hàm cần có trong functions
add_filter( 'wp_default_editor', create_function('', 'return "html";') );
function get_rid_of_wpautop(){
  if(!is_singular('post')){
    remove_filter ('the_content', 'wpautop');
    remove_filter ('the_excerpt', 'wpautop');
  }
}
add_action( 'template_redirect', 'get_rid_of_wpautop' );

Gọi post và bài mặc định
// Gọi bài post mặc định
<?php $args=array('post_type' => 'post', 'orderby' => 'ID', 'order'   => 'DESC', 'posts_per_page'=>5);$query = new WP_Query( $args); ?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post();?>
// Start loop news
 <span class="date"><?php the_time('Y.m.d') ; ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
// End loop news
<?php endwhile; ?>
<?php  wp_reset_query(); ?>
<?php  endif; ?>


// Gọi chi tiết nội dung bài post
<?php if ( have_posts() ) :  ?>
<?php while ( have_posts() ) : the_post(); ?>
 
        <span class="title">
        <?php the_title(); ?>
        </span>
     
        <span class="date">
        <?php the_time('Y.m.d') ; ?>
        </span>
     
        <span class="content">
        <?php the_content();  ?>
        </span>
     
    <?php endwhile; ?>
    <?php  wp_reset_query(); ?>
<?php  endif; ?>

// Gọi bài post theo category
<?php $args=array('category_name' => 'news', 'orderby' => 'ID', 'order'   => 'DESC', 'posts_per_page'=>3);$query = new WP_Query( $args); ?>
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post();?>
// Start loop news
 <span class="date"><?php the_time('Y.m.d') ; ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
// End loop news
<?php endwhile; ?>
<?php  wp_reset_query(); ?>
<?php  endif; ?>


// Gọi chi tiết nội dung bài post theo category
// Tạo single.php, trong file có code này
<?php $post = $wp_query->post;
if ( in_category( 'news') ) {
 include( TEMPLATEPATH.'/single-news.php' );
}
else if ( in_category( 'category_other') ) {
include( TEMPLATEPATH.'/single-category_other.php' );
}
?>

// Tạo file single-news.php rồi bỏ code này vào
<?php if ( have_posts() ) :  ?>
<?php while ( have_posts() ) : the_post(); ?>
        <span class="title">
        <?php the_title(); ?>
        </span>
        <span class="date">
        <?php the_time('Y.m.d') ; ?>
        </span>
        <a href="<?php the_permalink(); ?>">
<?php $cat = get_the_category(get_the_ID()); $name_cat = $cat[0]->cat_name; ?> // Gọi tên category  nếu cần
</a>
        <span class="content">
        <?php the_content();  ?>
        </span>
    <?php endwhile; ?>
    <?php  wp_reset_query(); ?>
<?php  endif; ?>



cắt content
// Khai báo function này trong file function
function cuttring($str, $length)
{
$str = trim($str);
$sections = preg_split("/[n]+/", $str);
$kq="";
foreach( $sections as $value )
{
$value = trim($value);
if( $value !='' )
if(!preg_match('#(?<=<)w+(?=[^<]*?>)#', $value)){
$kq .= $value;
break;
}    
}
return mb_substr($kq,0, $length,'utf-8')."...";
}

// Gọi content và giới hạn số kí tự xuất hiện
$content_blog = get_the_content();
echo cuttring( $content_blog, 80);

Cắt chuỗi PHP

Cắt chuỗi php không bị mất nghĩa , không bị $%  , tùy chọn độ dài cho chuỗi , hàm cắt php

Cái này là mình cũng sưu tầm được các bạn biết rồi thì hãy share cho những ai chưa biết nhé
Cách 1
<?php
function _substr($str, $length, $minword = 3)
{
$sub = '';
$len = 0;
foreach (explode(' ', $str) as $word)
{
    $part = (($sub != '') ? ' ' : '') . $word;
    $sub .= $part;
    $len += strlen($part);
    if (strlen($word) > $minword && strlen($sub) >= $length)
    {
      break;
    }
 }
    return $sub . (($len < strlen($str)) ? '...' : '');
}
?>
Hàm trên sẽ chèn thêm dòng “…”  vào chuỗi con mà chúng ta lấy ra, nó giống như hàm substr nhưng nó không cắt từng kí tự mà chỉ cắt ra từng câu.
Ví dụ chúng ta áp dụng nó như sau :
<?php
echo _substr('Chao Mung Ban Den Voi trungnguyenduy.blogspot.com',7);
?>
// xuất ra màn hình là “Chao Mung…”
Cách 2 :
<?php
function text_limit($str,$limit=10)
 {
 if(stripos($str," ")){
 $ex_str = explode(" ",$str);
 if(count($ex_str)>$limit){
 for($i=0;$i<$limit;$i++){
 $str_s.=$ex_str[$i]." ";
 }
 return $str_s;
 }else{
 return $str;
 }
 }else{
 return $str;
 }
 }
?>
Hàm trên hoạt động như sau:
– Chỉ định bao nhiêu câu mà bạn muốn hiển thị
– Tìm câu cuối cùng hiển thị là gì
– Nếu câu cuối không phải là khoảng trắng thì nó sẽ tìm đến câu kế tiếp và tìm cho đến khi thấy khoảng trắng.
– Hiển thị ra màn hình
Ví dụ dùng cho hàm trên như sau :
<?php
echo text_limit('Chao Mung Ban Den Voi 
trungnguyenduy.blogspot.com
',7); Xuất ra "Chao Mung Ban Den Voi
trungnguyenduy
" echo text_limit('Chao Mung Ban Den Voi
trungnguyenduy.blogspot.com
',3); Xuất ra "Chao Mung Ban"
?>