Welcome Guest, Not a member yet? Register   Sign In
Word limiter questions
#1

[eluser]mikegeorgeff[/eluser]
I am creating a blog application and I want to limit the number of words in the body of each blog post. How would I go about doing this.

Here is what I have so far:

Code:
function index()
    {
        $posts = new Post();
        $posts->order_by('id', 'desc');
        $data['posts'] = $posts->get();
        $this->load->view('admin/blog_index', $data);
        
        $this->output->enable_profiler(TRUE);
    }
#2

[eluser]InsiteFX[/eluser]
Here try this:

Creating a QuickStart Blog with CodeIgniter Electronic Version: US $6.99

Controller
Code:
function index()
{
    $data['posts']    = $this->posts_model->get_live_posts(10);
    $data['cats']    = $this->category_model->get_top_categories();
    $data['title']    = "Welcome";
    $data['main']    = 'public_home';
    
    $this->load->vars($data);
    $this->load->view('your view');
}

view
Code:
// application/config/autoload.php
$autoload['helper'] = array('url','form','text','date','typography');

// view file.
if (count($posts))
{
    foreach ($posts as $key => $data)
   {
    echo "<h2>".$data['title']."</h2>\n";
    echo auto_typography(word_limiter($data['body'], 200));
    echo anchor('blog/post/'.$data['id'], 'read more >>');
    }
    
    echo "<br /><br />";
}

// this is the magic above...
echo auto_typography(word_limiter($data['body'], 200));

InsiteFX
#3

[eluser]mikegeorgeff[/eluser]
Thank You, That worked great.
#4

[eluser]InsiteFX[/eluser]
Your very welcome.

I would purchase that blog for the $6.99 well worth it and it's
all coded in Active Record, very nice I learned a lot form it
last year.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB