How can I create expandable post summaries? With this trick, you can choose to display an arbitrary amount of text from the beginning of each post, as a teaser for the whole thing. Then users who want to read the rest of the post can click a link to see the full text. This is handy if you have lots of long articles all on one page. Note that you'll need to have post pages enabled in order to make this feature work. There are three ingredients that go into this feature: conditional CSS, a "read more" link for each post, and a modification for the posts that use this feature. So let's go through it step by step. We're going to use conditional tags to change how posts display on different pages. Add the following code to your style sheet, depending on what kind of template you have: What we did here was to define a class called "fullpost" that will appear only on post pages (permalinks). Part of each post will use this class, as we'll see later. This link will only appear on the main page and archive pages, and it will redirect your reader to the post page containing the full text of your post. You can replace the "Read more!" text with whatever you like, of course. The final piece that we need is a little bit of code in your actual post. Each post that you want to use this feature on will need this code: <span class="fullpost"></span> Now, when a reader visits your blog, this post will appear like this: Notes:
The Quick Answer
Conditional CSS
<MainOrArchivePage>
span.fullpost {display:none;}
</MainOrArchivePage>
<ItemPage>
span.fullpost {display:inline;}
</ItemPage>
(for layouts) សំរាប់ប្លុកដែលប្រើជាលក្ខណៈ layouts
សូមយកកូដនេះទៅដាក់ដូចរូបខាងក្រោម
<style>
<b:if cond='data:blog.pageType == "item"'>
span.fullpost {display:inline;}
<b:else/>
span.fullpost {display:none;}
</b:if>
</style>
Your style sheet is usually near the top of your template, between the <style> and </style> tags. If you have your style sheet in a separate file, you'll still need to add these lines in your template, so the conditional tags will work. Just make sure you add in the <style> tags around them. "Read More" Links
Add the following code to your template, somewhere after the សូមយកកូដខាងខាងក្រោម (ទៅតាមប្រភេទនៃTemplate) ទៅដាក់ខាងក្រោមនៃ (For Classis Search this ស្វែងរកពាក្យនេះ) <$BlogItemBody$> or (For Laout Search this ស្វែងរកពាក្យនេះ) <data:post.body/> tag:
(for classic templates)
<MainOrArchivePage><br />
<a href="<$BlogItemPermalinkURL$>">Read more!</a>
</MainOrArchivePage>
(for layouts)
<b:if cond='data:blog.pageType != "item"'><br />
<a expr:href='data:post.url'>Read more!</a>
</b:if>
សូមយកកូដនេះទៅដាក់ពីក្រោម <data:post.body/> ដូច្នេះ
<data:post.body/>
<b:if cond='data:blog.pageType != "item"'><br />
<a expr:href='data:post.url'>Read more!</a>
</b:if>Post Modifications
This part can actually go in the post template, if you don't want to have to type it for each post. You'll enter the summary text outside the span tags and the remainder inside, like so:
នៅរាល់ពេលអត្ថបទណាដែលអ្នកចង់ដាក់ឲ្យមាន Read More... សូមសេរសេរ ឲ្យមានលក្ខណៈដូចខាងក្រោមនេះ គឺ
ប្រសិនជាអ្នកចង់ចេញនៅទំព័រដើមឲ្យនៅខ្លី តាមដែលអ្នកចង់បាន
ឧទាៈ ខ្ញុំត្រូវការចង់ឲ្យចេញត្រឹមតែ
Here is the beginning of my post.
ហើយនៅពេលដែលយើងចុច Read More... វានឹងបង្ហាញទាំងអស់។
ដូច្នេះនៅពេលអ្នកចង់បានត្រឹមណា សូមដាក់កូដនេះ <span class="fullpost"> សិន សឹម សរសរតទៅ រហូតអស់សេចក្ដី ទើបបន្លែមកូដនេះ </span> ជាចុងក្រោយ។
សូមសាកល្បង យកអត្ថបទ និងកូដខាងក្រោមនេះសាកមើល!
Here is the beginning of my post. <span class="fullpost">And here is the rest of it.</span>Here is the beginning of my post.
When they click the link, they'll go to the post page where they'll see the whole thing:
Read more!Here is the beginning of my post. And here is the rest of it.
How can I add Expandable Post Summaries
Subscribe to:
Post Comments (Atom)
Hi brother socheat,
How are you doing ? I come to your blog almost every day and night. Your blog looks so cute and very helpful i learn a lot from it. well, because of you and your friends, Leo often help me, now i have my own blog. It looks not very nice but i try to improve. This is my blog: www.mahaburuskhmer.blogspot.com I really appreciate you and your help. Thank you
From Sem (choeun)