ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => หัวข้อเริ่มโดย: suntino ใน 10 พฤษภาคม 2014, 21:23:07

ชื่อเรื่อง: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: suntino ใน 10 พฤษภาคม 2014, 21:23:07
ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
(http://image.free.in.th/v/2013/ik/140510091113.png) (http://pic.free.in.th/id/1936a2bb4583f87f5758d3f7541b1913)

มันไม่ตัดคำภาษาไทยครับแต่ภาษาอังกฤษตัดคำปกติ theme eden fresh >>> hxxp://wpeden.com/preview/?product=MzU0NQ
พอดีผมทำไปเยอะไม่อยากเปลี่ยนทีมครับ ผมลองไล่codeดูไม่แน่ใจจะใช่codeนี่หรือเปล่า รบกวนท่านเทพทั้งหลายช่วยด้วยครับ

<div class="container">

    <div class="row-fluid">
        <div class="span3">
        <?php $tpid = (int)edenfresh_get_theme_opts('home_featured_page_1'); $intropage get_page($tpid); $introcontent strip_tags($intropage->post_content,"p,br"); if (preg_match('/^.{1,80}\b/s'$introcontent$match)) $introcontent $match[0];  ?>
        <div class="service-box">
          <div class="entry-content">
          <h3><span class="service-icon"><i class="icon icon-white icon-leaf"></i></span> <a href="<?php echo get_permalink($tpid); ?>"><?php echo $intropage->post_title?></a></h3>
          <?php echo $introcontent?>
          </div>
        </div> 
        </div>
       
        <div class="span3">
        <?php $tpid = (int)edenfresh_get_theme_opts('home_featured_page_2'); $intropage get_page($tpid); $introcontent strip_tags($intropage->post_content,"p,br"); if (preg_match('/^.{1,80}\b/s'$introcontent$match)) $introcontent $match[0];  ?>
        <div class="service-box">
          <div class="entry-content">
          <h3><span class="service-icon"><i class="icon icon-white icon-leaf"></i></span> <a href="<?php echo get_permalink($tpid); ?>"><?php echo $intropage->post_title?></a></h3>
          <?php echo $introcontent?>
          </div>
        </div> 
        </div>
       
        <div class="span3">
        <?php $tpid = (int)edenfresh_get_theme_opts('home_featured_page_3'); $intropage get_page($tpid); $introcontent strip_tags($intropage->post_content,"p,br"); if (preg_match('/^.{1,80}\b/s'$introcontent$match)) $introcontent $match[0];  ?>
        <div class="service-box">
          <div class="entry-content">
          <h3><span class="service-icon"><i class="icon icon-white icon-leaf"></i></span> <a href="<?php echo get_permalink($tpid); ?>"><?php echo $intropage->post_title?></a></h3>
          <?php echo $introcontent?>
          </div>
        </div> 
        </div>
       
        <div class="span3">
        <?php $tpid = (int)edenfresh_get_theme_opts('home_featured_page_4'); $intropage get_page($tpid); $introcontent strip_tags($intropage->post_content,"p,br"); if (preg_match('/^.{1,80}\b/s'$introcontent$match)) $introcontent $match[0];  ?>
        <div class="service-box">
          <div class="entry-content">
          <h3><span class="service-icon"><i class="icon icon-white icon-leaf"></i></span> <a href="<?php echo get_permalink($tpid); ?>"><?php echo $intropage->post_title?></a></h3>
          <?php echo $introcontent?>
          </div>
        </div> 
        </div>
    </div>

:wanwan044: :wanwan044: :wanwan044: :wanwan044:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: ThugzAffiliate ใน 10 พฤษภาคม 2014, 21:59:58
ง่ายๆ ครับไม่ต้องไปแก้โค๊ดให้ปวดหัว เข้า ไป edit post แล้วกด sceen options ติ๊กถูกหน้า Excerpt แล้วเลื่อนลงมาข้างล่าง อยากได้แบบไหนกี่คำ copy มาวางได้เลยครับ  :wanwan004:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: suntino ใน 10 พฤษภาคม 2014, 22:23:04
ลองทำแล้วไม่ได้ครับ มันไม่ตัดเหมือนเดิม
:wanwan017: :wanwan017: :wanwan017:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: fangbif ใน 10 พฤษภาคม 2014, 22:30:41
มันเป็นฟีเจอร์ของเรา เค้าให้เขียนแค่สั้นๆ รึเปล่าคะ ล่อไปซะยาวเชียว ประมาณว่า บริการของเรามีอะไรบ้าง แค่สั้นๆ
ปกติใช้ excerpt น่าจะตัด หรือไม่ก็ลองตัดด้วย more ดูนะคะ ตัดเอาที่ต้องการเลยค่ะ ของเราใช้ได้นะ  :wanwan012:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: Invoker ใน 10 พฤษภาคม 2014, 22:41:36
ภาษาไทยมันจะไม่ค่อยมีวรรคให้นับตอนตัดคำด้วย Excerpt ครับ ผมแนะนำให้ตัดด้วยการนับตัวอักษร และตามด้วย .... หรือไม่ก็  Read More>>> ดีกว่าครับ

<?php

$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...Read More</a>' );
echo $trimmed_content;

?>

ลองประยุกต์ใช้ดูนะครับ

ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: suntino ใน 10 พฤษภาคม 2014, 22:47:29
ปัญหาจริงๆๆคือมันไม่ตัดภาษาไทยครับ ที่ในรูปผมลองทำเปรียบเทียบให้ดูครับ ภาษาไทย 300 คำมันไม่ตัดคำ  ภาษาอังกฤษ 300 คำมันตัดคำ ผมลองใช้ moreคั่น ประโยคสั่นๆๆ มันก็ไม่ตัดครับ
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: suntino ใน 10 พฤษภาคม 2014, 22:48:26
เดียวขอลองดูครับ
:wanwan017: :wanwan017: :wanwan017: :wanwan017:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: Invoker ใน 10 พฤษภาคม 2014, 22:54:31
OK ครับ
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: blogupdating ใน 10 พฤษภาคม 2014, 22:59:00
รอเก็บความรู้ด้วยคน

:P
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: Peter002 ใน 10 พฤษภาคม 2014, 23:06:05
มาเก็บนิดหนวย  :wanwan004:
ชื่อเรื่อง: Re: ปวดหัว ปัญหา การตัดคำภาษาไทย wordpress ช่วยด้วยครับ
โพสต์โดย: suntino ใน 10 พฤษภาคม 2014, 23:43:33
ได้แล้วครับ ผมเข้าไปเพิ่มcodeที่ functions.php ใน theme ที่ใช้อยู่
function excerpt($limit) {
 $excerpt = explode(' ', get_the_excerpt(), $limit);
 if (count($excerpt)>=$limit) {
   array_pop($excerpt);
   $excerpt = implode(" ",$excerpt).'...';
 } else {
   $excerpt = implode(" ",$excerpt);
 }
 $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
 return $excerpt;
}

function content($limit) {
 $content = explode(' ', get_the_content(), $limit);
 if (count($content)>=$limit) {
   array_pop($content);
   $content = implode(" ",$content).'...';
 } else {
   $content = implode(" ",$content);
 }
 $content = preg_replace('/[.+]/','', $content);
 $content = apply_filters('the_content', $content);
 $content = str_replace(']]>', ']]&gt;', $content);
 return $content;
}


แล้วก้อนำcodeนี้
<?php echo excerpt(40); ?>
ไปใส่ในหน้า index.php หรือหน้า archive.php หรือหน้า category.php และตำแหน่งที่ต้องการแสดงผลตามต้องการเลยครับ
และถ้าต้องการให้มันตัดคำยาวขึ้นหรือสั้นลงเปลี่ยนค่าที่ 40 จะมากหรือน้อยแล้วแต่ตามสะดวกครับ

ส่วนผมลองทำที่หน้าadmin แล้วไม่ได้ผล ตามวิธีที่เพื่อนสมาชิกแนะนำ ขอขอบคุณทุกๆๆคนครับ  :wanwan017: :wanwan017: :wanwan017:  :wanwan017: :wanwan017: :wanwan017: