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 post
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 post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.