ModuleBuilder::Navbar PHP Method

Navbar() public static method

导出导航模块数据
public static Navbar ( ) : string
return string 模块内容
    public static function Navbar()
    {
        global $zbp;
        $template = $zbp->template;
        $tags = array();
        $s = $zbp->modulesbyfilename['navbar']->Content;
        $a = array();
        preg_match_all('/<li id="navbar-(page|category|tag)-(\\d+)">/', $s, $a);
        $b = $a[1];
        $c = $a[2];
        foreach ($b as $key => $value) {
            if ($b[$key] == 'page') {
                $type = 'page';
                $id = $c[$key];
                $o = $zbp->GetPostByID($id);
                $url = $o->Url;
                $name = $o->Title;
                $a = '<li id="navbar-' . $type . '-' . $id . '"><a href="' . $url . '">' . $name . '</a></li>';
                $s = preg_replace('/<li id="navbar-' . $type . '-' . $id . '">.*?<\\/a><\\/li>/', $a, $s);
            }
            if ($b[$key] == 'category') {
                $type = 'category';
                $id = $c[$key];
                $o = $zbp->GetCategoryByID($id);
                $url = $o->Url;
                $name = $o->Name;
                $a = '<li id="navbar-' . $type . '-' . $id . '"><a href="' . $url . '">' . $name . '</a></li>';
                $s = preg_replace('/<li id="navbar-' . $type . '-' . $id . '">.*?<\\/a><\\/li>/', $a, $s);
            }
            if ($b[$key] == 'tag') {
                $type = 'tag';
                $id = $c[$key];
                $o = $zbp->GetTagByID($id);
                $url = $o->Url;
                $name = $o->Name;
                $a = '<li id="navbar-' . $type . '-' . $id . '"><a href="' . $url . '">' . $name . '</a></li>';
                $s = preg_replace('/<li id="navbar-' . $type . '-' . $id . '">.*?<\\/a><\\/li>/', $a, $s);
            }
        }
        $tags['content'] = $s;
        $template->SetTagsAll($tags);
        $ret = $template->Output('module-navbar');
        return $ret;
    }

Usage Example

Esempio n. 1
0
function BuildModule_navbar()
{
    return ModuleBuilder::Navbar();
}