Jump to content

Excerpts - Pull content into column, 100 characters max


jenniferabel

Recommended Posts

Hi guys, 

I have created a column in my table titled "excerpts." Just as the name suggests, I'm hoping to create excerpts of each post in my blog with a max of 100 characters. I'm using phpmyadmin, and it seems to automatically generate "0" in my excerpts column, as you'll see on my site here: https://www.visabel.ca/index.php

Here is the code I have. I'm not quite sure what to write here for excerpts, so bare with me:

$sql = "SELECT b.id, b.title, c.name AS category, b.tags, content, b.excerpt, photo, b.date AS pubDate, \"Jennifer\" AS author FROM blogs AS b LEFT JOIN blog_categories c ON b.category=c.id WHERE posted=\"publish\" ORDER BY DATE DESC limit 2;";
                        $result = $conn->query($sql);
                        
                        if ($result->num_rows > 0) {
                          // output data of each row
                          while($row = $result->fetch_assoc()) {
                              echo'

--------------------------

Please help! I've scoured the 'net and can't find the solution I'm looking for. 

Link to comment
Share on other sites

Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt.

$sql = "SELECT b.id
             , b.title
             , c.name AS category
             , b.tags
             , content
             , LEFT(content, 100) as excerpt
             , photo
             , b.date AS pubDate
             , 'Jennifer' AS author 
        FROM blogs AS b 
             JOIN 
             blog_categories c ON b.category=c.id 
        WHERE posted = 'publish' 
        ORDER BY DATE DESC 
        LIMIT 2
        ";

 

Link to comment
Share on other sites

42 minutes ago, Barand said:

Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt.


$sql = "SELECT b.id
             , b.title
             , c.name AS category
             , b.tags
             , content
             , LEFT(content, 100) as excerpt
             , photo
             , b.date AS pubDate
             , 'Jennifer' AS author 
        FROM blogs AS b 
             JOIN 
             blog_categories c ON b.category=c.id 
        WHERE posted = 'publish' 
        ORDER BY DATE DESC 
        LIMIT 2
        ";

 

Hi Barand, I tried that previously but it still didn't display my excerpt. I'm not sure what's going on...

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.