Jump to content

[Ask] [CodeIgniter] How to create preview post


Orasion

Recommended Posts

Hi all,

 

im new member here and also new to php world. I use CI to learn.

I copy paste the article from my wordpress blog and found <p><!--more--></p> tag but I dont know how to hide post after that tag to create preview post just like in wordpress, can you give me some advice to do that?

 

really appreciate your help,

thx

Link to comment
Share on other sites

first load the text helper, either auto load it or load it in the constructor in the controller.

 

then use the following function:

word_limiter($string, 10);

where the 10 is the number of words that will display

 

a sample post would look like the following in the view file

<?php foreach ($posts as $p): ?>
<h2><?php echo $p['title']; ?></h2>
<p><?php echo word_limiter($p['body'], 25); ?></p>
<?php echo anchor('blog/post/'.$p['id'], 'Read More >>>');
<?php endforeach; ?>

 

The second to last line of code will create a link to the full blog article

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.