-3

投稿のカテゴリをチェックする関数(PHP5プログラミング)を見つけようとしていますが、その結果に応じて(ホームページで)そのパーツスタイル(背景色)が変わります。

どこから始めたらいいのかわからない。なにか提案を ?

(私はWORDPRESSを使用していません)

ありがとう。

4

1 に答える 1

0

CSSを使用してそれを達成できます。カテゴリに基づいて、投稿に適切なクラスを追加するだけです。


とにかく、heereはカテゴリに応じて背景色を変えるものの例です。これを出発点として使用できます

ポストクラスのモックアップ

    class Post {
        public $text;
        public $category;
        public $style;

        public function __construct($text, $category) {
            $this->text = $text;
            $this->category = $category;
            $this->changeBg($category);
        }

        public function outputHTML() {
            return "<div class=\"category-{$this->category}\" style=\"{$this->style}\">{$this->text}</div>";
        }

        public function changeBg($category) {
            switch ($category) {
                case 'cat1':
                   $this->style = 'background-color: red';
                   break;
            }
        }

        public function __toSTring() {
            return $this->outputHTML();
        }
    }

ホームページ

$post = new Post('this is a post blabla', 'cat1');
print $post;
于 2013-02-07T20:10:24.643 に答える