chainmon
V2EX  ›  问与答

typecho 模板中的这种优雅格式如何实现呢?

  •  
  •   chainmon · Jan 2, 2017 · 3259 views
    This topic created in 3446 days ago, the information mentioned may be changed or developed.
    <div class="main">
        <?php if($this->have()):?>
            <?php while($this->next()): ?>
            <article>
                <p class="title"><a href="<?php $this->permalink() ?>" target="_blank"><?php $this->title() ?></a></p>
                <span class="date">发布于:<?php $this->date('y-m-d'); ?></span>
                <span class="author">来自<a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a></span>
                <div class="category"><?php $this->category(','); ?></div>
                <div class="content"><?php $this->content('阅读全文 >>'); ?></div>
            </article>
            <?php endwhile; ?>
        <?php else:?>
            <div>暂无文章</div>
        <?php endif?>
        <?php $this->pageNav('<< 上一页', '下一页 >>'); ?>
    </div>
    

    感觉这种格式可自定义化很高啊,即使小白也会用,重组性也挺高的

    8 replies    2017-01-02 12:26:29 +08:00
    Tink
        1
    Tink  
    PRO
       Jan 2, 2017 via iPhone
    这不是 php ?
    chainmon
        2
    chainmon  
    OP
       Jan 2, 2017
    @Tink 是类似于这样的格式 $this->have()
    xfspace
        3
    xfspace  
       Jan 2, 2017 via Android
    看 Controller 的实现
    Syc
        4
    Syc  
       Jan 2, 2017 via Android
    @chainmon 熟人你好(逃
    onlyhot
        5
    onlyhot  
       Jan 2, 2017 via iPhone
    一点都不优雅
    SuperMild
        6
    SuperMild  
       Jan 2, 2017
    JSX 更优雅啊
    Balthild
        7
    Balthild  
       Jan 2, 2017
    WordPress:

    https://gist.github.com/balthild/4cc61f5ba1f34cc6817956090c74cd97

    形式只是外在,套路都是一样的。
    Balthild
        8
    Balthild  
       Jan 2, 2017
    补充:这种所谓的「主循环」其实类似于一个 STL 迭代器,如果你搞过 C++,理解起来会容易得多。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5364 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 07:35 · PVG 15:35 · LAX 00:35 · JFK 03:35
    ♥ Do have faith in what you're doing.