Hello, I got problem to write code excerpt in my article.

CREATE TABLE IF NOT EXISTS 'articles' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'title' varchar(250) NOT NULL,
'body' text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

INSERT INTO 'articles' ('id', 'title', 'body') VALUES
(1, 'Lorem', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.');

Article class

class Article_class {
  protected static $table_name = 'articles';
  public $id, $title, $body;
    public static function get_articles() {
      try {
        global $database_handle;
        $sql = "SELECT * FROM " . self::$table_name;
        $statement = $database_handle->sql_query($sql);
        $statement->setFetchMode(PDO::FETCH_OBJ);
        while($row = $statement->fetch()) {
          $data[] = $row;
        }
        return $data;
      } catch(PDOException $pdo_exception) {
        die("Error " . $pdo_exception->getMessage());
      }
    }
}

That code is working fine in my view template, What I really want is how to create the excerpt for 5 line. I already search in Google, but I can't find it, too many Wordpress excerpt code.

Btw where is the seacrh form, I can't find, in top is for all, not for PHP only.

Recommended Answers

All 3 Replies

5 lines ? Do you mean you want to truncate after the fifth dot ?

Yeah, you're correct, after the fifth dot.

Actually, it doesn't really matter how many line or like you said truncate after dot, because I think it would be dynamic as a parameter.

Anyway in wordpress I see the trick is just add comment "<!--more-->" in the textarea, not sure, but I think wordpress use tinyMCE.

Well, putting a marker like you say is much easier. But you would have to add it when saving your data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.