readmore
 

บทความตัวนี้จะเป็นการแนะนำเทคนิคการโมธีม wordpress ในการใส่ปุ่ม Read more หรือปุ่มอ่านต่อ นั่นเอง ซึ่งธีมหลายๆตัวจะไม่มี เราก็ต้องมาโมเพิ่มเองนะครับ คำเตือนกรุณาแบ็คอัพไฟลืไว้กันพลาดนะครับ

การโมเพิ่มปุ่ม อ่านต่อนี้ ผมจะแนะนำเทคนิดง่ายๆเพราะ ให้สามารถทำตามและปรับแต่งได้ตามใจชอบ วึ่งในตัวอย่างอาจจะไม่สวยเท่าไหร่ นะครับ อยากให้สวยก็ขึ้นกับไอเดียของแต่ละคนแล้วหละครับ

มาดูขั้นตอนแรก จะเป็นการเพิ่ม ฟังก์ชั่นการตัดทอนโพสให้สั้นลงตามที่เราต้องการก่อน เปิดไฟล์ functions.php แล้วเพิ่มต่อไปนี้ครับ

function the_content_limit($max_char, $more_link_text = '(more…)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0) {
      echo "<p>";
      echo $content;
      echo "&nbsp;<a href='";
      the_permalink();
      echo "'>"."Read More &rarr;</a>";
      echo "</p>";
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo $content;
        echo "…";
       
   }
   else {
      echo "<p>";
      echo $content;
      echo "&nbsp;<a href='";
      the_permalink();
      echo "'>"."…</a>";
      echo "</p>";
   }
}

เมื่อเพิ่มโคดเสร็จแล้วก็เวฟให้เรียบร้อยครับ ต่อมาก็แก้ไขการแสดงบทความในส่วนของ index.php ครับ ซึ่งแต่ละธีมจะมีโคดไม่เหมือนกัน ดังนั้นผมจะเอาโคดที่คิดว่าน่าจะพอทำให้เราเข้าใจละกันครับ

โคดเดิมนะครับ อาจจะไม่เหมือนกับตัวอย่างแต่ก็คล้ายๆกันครับ

<?php while (have_posts()) : the_post(); ?>
                    <!– Start: Post –>
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <p class="postmeta">Posted on <a href="<?php the_permalink() ?>"><?php the_time( get_option( 'date_format' ) ) ?></a> by <?php the_author() ?></p>  

     
<div class="entryContent">
<?php the_post_thumbnail(); ?>
<?php the_excerpt(); ?>
</div>

ตรงส่วนนี้จะเป็นการแสดงบทความและรูปภาพซึ่งคือส่วนที่เราจะแก้ไข

                        <p>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </p>
                    </div>
                    <div class="clear"></div>
                    <!– End: Post –>
                <?php endwhile; ?>

ให้แก้โคดดังนี้

<?php while (have_posts()) : the_post(); ?>
                    <!– Start: Post –>
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <p class="postmeta">Posted on <a href="<?php the_permalink() ?>"><?php the_time( get_option( 'date_format' ) ) ?></a> by <?php the_author() ?></p>        

<div class="entryContent">
<?php the_post_thumbnail(); ?>

กำหนดจำนวนตัวอักษรบทความที่จะแสดง ในตัวอย่างผมตั้งไว้ที่ 300 ตัวอักษร
<?php the_content_limit(300, ''); ?>

ปุ่ม อ่านต่อ สามารถเอาโคดนี้ไปวางส่วนไหนก็ได้เพื่อความสวยงาม จะตะแคงซ้าย ขวา หน้า หลังก็ตามแต่ครับ โดยรูปที่ใช้เป็นปุ่มชื่อ readmore.png
<a href="<? the_permalink(); ?>" ><img src="<?php bloginfo('template_directory'); ?>/images/readmore.png" border="0"  width="100"/></a>

</div>
                        <p>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </p>
                    </div>
                    <div class="clear"></div>
                    <!– End: Post –>
                <?php endwhile; ?>

ลองเอาไปศึกษาดูครับ ส่วนจะสวยไม่สวยก็ขึ้นอยู่กับไปเดียและการปรับแต่ง css ครับ

Comment

Comment:

Tweet

#712 By สติ๊กเกอร์ไลน์ (183.89.83.82|183.89.83.82) on 2014-11-28 12:02

Các tập truyện doremon màu mới nhất đây truyen doremon co mau || truyen tranh doremon tap 4 || doc truyen doremon mien phi || truyện doremon màu

#711 By Hương ngọc on 2014-09-11 16:23

Chơi game thật đã chỉ có trong: game kim cuong mien phi
Game hot nhât hiện nay: tai game angry birds cho điện thoại

#710 By game dot kich mien phi (42.113.49.247|42.113.49.247) on 2014-03-18 16:53

download zalo chat nhắn gửi yêu thương
Tận hưởng cảm giác yomoot! với kho hình động ngộ nghĩnh và hài hước khi: download chat zalo
Chơi game thật đã chỉ có trong: game kim cuong mien phi
Game hot nhât hiện nay: tai game angry birds cho điện thoại

#709 By game kim cuong mien phi (42.113.49.247|42.113.49.247) on 2014-03-10 14:36

download zalo chat nhắn gửi yêu thương
Tận hưởng cảm giác yomoot! với kho hình động ngộ nghĩnh và hài hước khi: download chat zalo
Chơi game thật đã chỉ có trong: game kim cuong mien phi
Game hot nhât hiện nay: tai game angry birds cho điện thoại

#708 By marylove (113.23.12.17|113.23.12.17) on 2014-03-06 15:40

Fed up with all japan announcements? We are on this site to suit your needs!

#707 By ???????? (198.27.85.187) on 2013-11-15 05:27

Avec le Juillet 27 signature du 60e anniversaire de l'armistice de la guerre de Core Accord aube de Core ont lanc une varit de clbrations, et s'efforcer de crer une? victoire sur le festival ?atmosphre?. Sud-corenne YTN tlvision le 24 rapport que la Core du Nord a galement invit, y compris les principaux mdias aux journalistes du monde entier, chinois l'tranger, et d'autres dlgations jusqu' 3.000 personnes. 23 Yonhap a rapport que, en plus de la prochaine parade militaire massif 27, la RPDC tiendra des manifestations de masse grande chelle, tout en maintenant la parade militaire et des manifestations de masse sont trs rares en Core du Nord, les deux derniers dtenus guerre de Core simultanment ou 1993 40e anniversaire de la signature de l'Accord d'armistice. Jiji agence de nouvelles du Japon a dclar la Core du Nord cherche "battre Day" de campagne, le Korean Air Koryo a eu trois fois par semaine destination et partir de Pyongyang Pkin, a t port un maximum de cinq allers-retours par jour, la Core du Nord trains internationaux capacits a galement augment. Ont rapport que les annes prcdentes, les activits mettent l'accent diffrent RPDC amical, la Core clbrations de cette anne pour d'autres pays de montrer une image de bonne volont, le dsir de diminuer les essais nuclaires en Fvrier de cette anne encourus pression internationale.
Ralph Lauren Homme http://ralphlaurenhommer.moonfruit.fr/

#706 By Ralph Lauren Homme (112.111.185.137) on 2013-11-13 19:00

Avec le Juillet 27 signature du 60e anniversaire de l'armistice de la guerre de Core Accord aube de Core ont lanc une varit de clbrations, et s'efforcer de crer une? victoire sur le festival ?atmosphre?. Sud-corenne YTN tlvision le 24 rapport que la Core du Nord a galement invit, y compris les principaux mdias aux journalistes du monde entier, chinois l'tranger, et d'autres dlgations jusqu' 3.000 personnes. 23 Yonhap a rapport que, en plus de la prochaine parade militaire massif 27, la RPDC tiendra des manifestations de masse grande chelle, tout en maintenant la parade militaire et des manifestations de masse sont trs rares en Core du Nord, les deux derniers dtenus guerre de Core simultanment ou 1993 40e anniversaire de la signature de l'Accord d'armistice. Jiji agence de nouvelles du Japon a dclar la Core du Nord cherche "battre Day" de campagne, le Korean Air Koryo a eu trois fois par semaine destination et partir de Pyongyang Pkin, a t port un maximum de cinq allers-retours par jour, la Core du Nord trains internationaux capacits a galement augment. Ont rapport que les annes prcdentes, les activits mettent l'accent diffrent RPDC amical, la Core clbrations de cette anne pour d'autres pays de montrer une image de bonne volont, le dsir de diminuer les essais nuclaires en Fvrier de cette anne encourus pression internationale.
doudoune ralph lauren pas cher http://doudouneralphlaurenpascherr.moonfruit.fr/

#705 By doudoune ralph lauren pas cher (112.111.185.137) on 2013-11-13 18:21

Alors que la flotte de navette spatiale amricaine entirement dsarm entreprises NASA et le rail et le Space Exploration Technologies Corporation en Californie (SpaceX) contract leur charg de ravitailler la station spatiale.
ralph lauren pas cher http://doudouneralphlaurenr.moonfruit.fr/

#704 By ralph lauren pas cher (175.42.94.253) on 2013-11-13 05:36

Laisser au moins 499 nouvelles marques construisent moins limite remise 100LevisI.T 30% par Aubaines
Chemise Burberry Pas cher http://pullburberry.moonfruit.fr/

#703 By Chemise Burberry Pas cher (27.159.200.105) on 2013-11-12 16:14

Descriptions displayed inside the Drive 2007 model within the "Journal from Farming plus Nutrition Chemistry" indicated that the Native english speakers yew possesses raspberry ketones found throughout it has the building...
moncler men jackets http://www.markagent.net/node/9

#702 By moncler men jackets (120.33.220.204) on 2013-11-12 15:50

<a href="http://doudounesralphlaurenhommepascher.moonfruit.fr/" title="doudoune ralph lauren homme">doudoune ralph lauren homme</a>|<a href="http://doudounesralphlaurenhommepascher.moonfruit.fr/" title="doudoune ralph lauren femme">doudoune ralph lauren femme</a>|<a href="http://doudounesralphlaurenhommepascher.moonfruit.fr/" title="doudoune ralph lauren homme pas cher">doudoune ralph lauren homme pas cher</a>|
doudoune ralph lauren,doudoune ralph lauren pas cher http://doudounesralphlaurenhommepascher.moonfruit.fr

#701 By doudoune ralph lauren,doudoune ralph lauren pas cher (218.6.8.173) on 2013-11-10 16:24

Do you ever are lacking management? Not any..
celine handbags http://www.curiousitivity.com

#700 By celine handbags (198.56.241.52) on 2013-11-10 04:28

<a href="http://www.franceMoncler.net/monclerfrance+monclerparis.html" title="moncler france">moncler france</a>

#699 By pull moncler pas cher (61.147.99.33) on 2013-11-09 06:01

I gotta favorite this internet site it seems handy handy

#698 By Michael Kors Sverige (61.147.123.12) on 2013-11-09 05:39

Good day! This is my first comment here so I just wanted to give a quick shout out and tell you I really enjoy reading your blog posts. Can you recommend any other blogs/websites/forums that cover the same subjects? Thanks a ton!
?????? ?????? http://tokei.setapartmingb.org/kakio-casio

#697 By ?????? ?????? (62.210.202.235) on 2013-11-09 03:05

BEIJING, 18 septembre (Xinhua) Selon des mdias amricains, les Etats-Unis Orbital Sciences Corporation (Orbital Sciences Corp) 18 date sera le premier lancement habit rapprovisionnement vaisseau spatial vers la Station spatiale internationale, et le seul Amricain sur les astronautes internationaux de la Station spatiale attendons avec impatience de venir envoy de chocolat frais.
hippodrome de longchamp http://www.magasinersac.com/

#696 By hippodrome de longchamp (175.44.54.56) on 2013-11-08 18:13

With havin so much content do you ever run into any problems of plagorism or copyright violation? My blog has a lot of unique content I've either created myself or outsourced but it seems a lot of it is popping it up all over the internet without my authorization. Do you know any methods to help prevent content from being stolen? I'd truly appreciate it.
www.benzvoip.com http://www.benzvoip.com/

#695 By www.benzvoip.com (62.210.202.241) on 2013-11-08 15:50

Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my comment didn't appear. Grrrr... well I'm not writing all that over again. Anyway, just wanted to say excellent blog!
ahnuu.com http://www.ahnuu.com/

#694 By ahnuu.com (62.210.202.241) on 2013-11-08 15:20

Hmm is anyone else encountering problems with the images on this blog loading? I'm trying to determine if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated.
??????????? http://www.bulmerica.com/????-cx-3.html

#693 By ??????????? (62.210.202.241) on 2013-11-08 15:20

BEIJING, 18 septembre (Xinhua) Selon des mdias amricains, les Etats-Unis Orbital Sciences Corporation (Orbital Sciences Corp) 18 date sera le premier lancement habit rapprovisionnement vaisseau spatial vers la Station spatiale internationale, et le seul Amricain sur les astronautes internationaux de la Station spatiale attendons avec impatience de venir envoy de chocolat frais.
sac longchamp pas cher http://sac-longchamp-pliage.blogspot.com/

#692 By sac longchamp pas cher (175.44.55.23) on 2013-11-07 20:30

autant de dchets. " Vu Xu Cheng Cheng manger biens essence , la conclusion n'a pas l'intention Qiaozai Yun Xu Cheng Cheng rgl ses esprits . Il se surprit penser un peu plus pratique , et elle est vraiment ncessaire.
franklin marshall homme pas che http://franklinmarshallhommepascher.moonfruit.fr

#691 By franklin marshall homme pas che (110.85.102.20) on 2013-11-07 05:02

S .|Us|States|America|North america|American|The united states|North american} Currently is already by means of {Facebook|Myspace|Fb|Facebook or myspace|Twitter|Zynga|Facebook or twitter|Facebook .
moncler jackets http://www.markagent.net

#690 By moncler jackets (23.244.230.122) on 2013-11-07 00:57

Astronaute de la NASA Karen? Ni Boge (Karen Nyberg) dit qu'elle ne peut pas attendre pour d'autres engins spatiaux "Swan" (Cygne) est arriv. Elle a dit qu'il a envoy les colis pour la maison et peut-tre obtenir des plats spciaux sont trs excits.
doudoune ralph lauren pas cher http://www.demarquesmagasin.com/

#689 By doudoune ralph lauren pas cher (175.44.55.23) on 2013-11-06 21:48

live as if you were to die tomorrow. Learn as if you were to live forever
impact crusher http://www.alibaba.com/product-gs/884355114/2013_hot_selling_impact_crusher_used.html

#688 By impact crusher (218.28.140.186) on 2013-11-06 13:08

Wow that was odd. I just wrote an very long comment but after I clicked submit my comment didn't appear. Grrrr... well I'm not writing all that over again. Anyhow, just wanted to say great blog!
??? ???? http://www.clotheswed.com/herno

#687 By ??? ???? (62.210.202.240) on 2013-11-06 02:20

Kitchen counter, found at 105 Initially.
celine handbags http://www.curiousitivity.com

#686 By celine handbags (23.244.230.113) on 2013-11-05 15:49

Alors que la flotte de navette spatiale amricaine entirement dsarm entreprises NASA et le rail et le Space Exploration Technologies Corporation en Californie (SpaceX) contract leur charg de ravitailler la station spatiale.
Ralph Lauren Soldes http://burberrypascher.cc/

#685 By Ralph Lauren Soldes (175.42.87.248) on 2013-11-05 14:52

With havin so much written content do you ever run into any issues of plagorism or copyright infringement? My website has a lot of exclusive content I've either authored myself or outsourced but it looks like a lot of it is popping it up all over the internet without my agreement. Do you know any methods to help prevent content from being ripped off? I'd definitely appreciate it.
Wave Ceptor Casio http://www.ahnuu.com/???wave-ceptor-?????-outletjp-28.html

#684 By Wave Ceptor Casio (62.210.202.241) on 2013-11-05 09:20

Just wanna admit that this is extremely helpful, Thanks for taking your time to write this.
seiko ??? http://watch.bahroooo.com/

#683 By seiko ??? (62.210.202.26) on 2013-11-03 19:58

The amount of weight bearing will depend on range from the water where by treatment method done...
celine handbag http://www.curiousitivity.com

#682 By celine handbag (120.37.238.181) on 2013-11-03 19:51

Hello this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I'm starting a blog soon but have no coding skills so I wanted to get advice from someone with experience. Any help would be greatly appreciated!
GUCCI ?? http://www.djduro.net/gucci-???-tokei-10.html

#681 By GUCCI ?? (62.210.202.241) on 2013-11-03 19:38

Hello! I could have sworn I've been to this site before but after browsing through some of the post I realized it's new to me. Anyhow, I'm definitely delighted I found it and I'll be bookmarking and checking back often!
??????? http://www.mojzwierz.net/???????-se-1.html

#680 By ??????? (62.210.202.241) on 2013-11-03 18:22

I would like this!!!

#679 By bottes neige femme vieux campeur (202.105.61.227) on 2013-11-03 10:00

This design is spectacular! You most certainly know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Great job. I really loved what you had to say, and more than that, how you presented it. Too cool!
???????? http://www.lfcool.net/??????-love-4.html

#678 By ???????? (62.210.202.241) on 2013-11-03 03:55

Thanks for the marvelous posting! I quite enjoyed reading it, you can be a great author.I will be sure to bookmark your blog and will eventually come back sometime soon. I want to encourage you continue your great writing, have a nice holiday weekend!
??? ????? ?? http://watch.uwwpikes.org/oceanus-fashion-watchoutlet-15.html

#677 By ??? ????? ?? (62.210.202.241) on 2013-11-03 03:55

Incredible! This blog looks exactly like my old one! It's on a entirely different topic but it has pretty much the same page layout and design. Wonderful choice of colors!
?????? ?? http://www.fashionjpdown.com/

#676 By ?????? ?? (62.210.202.240) on 2013-11-03 01:45

You may additionally try to eat popsicles as well as gelatin treats.
www.csuzetas.com http://www.csuzetas.com

#675 By www.csuzetas.com (23.244.230.98) on 2013-11-02 10:04

My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using WordPress on numerous websites for about a year and am concerned about switching to another platform. I have heard good things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any help would be greatly appreciated!
???????? ? http://www.solariumbg.net/?timberland?????????-c-7.html

#674 By ???????? ? (62.210.202.241) on 2013-11-02 03:16

D'Artagnan ouvrit vivement le papier et le regarda à deux fois. Il ne

#673 By ugg soldes (175.44.11.178) on 2013-11-01 20:30

Hey there! I've been following your site for some time now and finally got the bravery to go ahead and give you a shout out from Dallas Tx! Just wanted to mention keep up the excellent job!
???? ??? ?? http://www.balenotokei.com/????bvlgari-jp-8.html

#672 By ???? ??? ?? (62.210.202.241) on 2013-11-01 12:27

cela, Sire ?

#671 By polos lacoste (175.44.11.178) on 2013-11-01 07:35

I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz answer back as I'm looking to construct my own blog and would like to know where u got this from. cheers
????????? http://www.watchlikey.com/gasioa

#670 By ????????? (62.210.202.240) on 2013-11-01 02:51

repentir d'avoir tiré l'épée pour moi.

#669 By lacoste pas cher (175.44.11.178) on 2013-11-01 02:24

Good day! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I'm getting fed up of Wordpress because I've had problems with hackers and I'm looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.
?????? ?? http://www.fashionjpdown.com/moncler

#668 By ?????? ?? (62.210.202.240) on 2013-10-31 14:56

I know this if off topic but I'm looking into starting my own weblog and was wondering what all is needed to get setup? I'm assuming having a blog like yours would cost a pretty penny? I'm not very web savvy so I'm not 100% positive. Any suggestions or advice would be greatly appreciated. Thanks
???? ???? http://www.fashionjpdown.com/

#667 By ???? ???? (62.210.202.240) on 2013-10-31 14:56

Today, while I was at work, my cousin stole my apple ipad and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!
??? ???? http://www.brandbagweb.com/coach-kaban

#666 By ??? ???? (62.210.202.240) on 2013-10-31 14:54

Greetings! This is my first comment here so I just wanted to give a quick shout out and tell you I truly enjoy reading through your articles. Can you suggest any other blogs/websites/forums that go over the same topics? Thanks a lot!
macalpinehua.com http://www.macalpinehua.com/

#665 By macalpinehua.com (62.210.202.240) on 2013-10-31 14:52

Mais manger plus large lui ce qui s'tait pass , il n'tait pas lui qui, ? Zaiyun camarades Qiao , je pense que les deux d'entre nous il n'ya pas de langue commune , que cette runion se terminera ici , je suis heureux de vous conna?tre , du jamais vu . "
montre armani homme http://montrearmanihomme.moonfruit.fr

#664 By montre armani homme (27.159.198.22) on 2013-10-31 09:11