Menu

Development theme

This article was last updated 37 days ago, please note whether the content is still available

File Structure (Themes)

The following is based on the initial files generated by "Create App":

/path/zb_users/theme/demoTheme
│  screenshot.png [Required] Thumbnail 320*240 pixels, landscape;
│  theme.xml      [Required] Description file;
│  main.php       [Optional] Application built-in management page, generated only if filled in during theme creation;
│  include.php    [Optional] Application embedded page, generated only if filled in during theme creation;
│
├─compile         [Deprecated] Old version z-blog used to place template compilation files, can be deleted directly;
├─include         [Optional] Theme's own "File Modules", use {module:abc} to "embed and call" the abc.php file in this directory;
├─script          [Optional] JS directory;
├─style           [Required] Style directory, stylesheet and required images;
│      style.css  [Required] Not limited to this filename, a theme can also have multiple styles (used independently);
│
├─css             [Optional] Not automatically created, used for style content that should not be placed in the style folder;
└─template        Used to store template files; it is recommended to prioritize the following 6 template files and their content;
       index.php  Homepage and list page
       single.php Article page (single page)
       search.php Search results page, uses index.php if not found
       header.php Common header file
       footer.php Common footer file
       404.php    Recommended to set

Main Entry Templates

By default, the system will only attempt to directly call the four template files index.php, single.php, search.php, and 404.php (if they exist);

Other templates are combined into the "main template" through "embedded calls";

Example

  • Theoretically, the following example can be used as the basic structure for the four "main template" files; except for the "Your Code" section;

  • {template:header}, {template:footer}, {template:sidebar} are commonly used templates within the "Z-BlogPHP system", and {template:hero} can be freely named to split code for corresponding positions; ("Writing Templates - Embedded Calls")

  • For details on "Template Description Information", "Embedded Calls", "Variable Output Tags", etc., please refer to: "Writing Templates"

{* Template Name: Homepage and list page * Template Type: index|list *}
<!-- ↑ "Template Description Information", including compatible "page types", placed on the first line of the template file -->
<!DOCTYPE html>
<html lang="{$language}"><!-- {$language} is a "Variable Output Tag" -->

<head>
  {template:header}<!-- Common header file -->
</head>

<body class="{$type}"><!-- Also a "Variable Output Tag", corresponding to the Template Type above -->
  {template:hero}
  <!-- ↓Your Code↓ -->
  <!-- ↓Your Code↓ -->
  <div id="divNavBar">
    <!-- Navigation "Module" Call -->
    <ul>{module:navbar}</ul>
  </div>
  <div id="divMiddle">
    <div id="divMain">List index or main content</div>
    <!-- "Sidebar" Call -->
    <div id="divSidebar">{template:sidebar}</div>
  </div>
  <!-- ↑Your Code↑ -->
  <!-- ↑Your Code↑ -->
  {template:footer}<!-- Common footer file -->
</body>

</html>

Template Files and Default Mechanism

  • Due to the "reserved template" mechanism, if a theme does not provide a certain template file, the system will read and use it from zb_system/defend/default; "View Online"

  • Therefore, some template files that do not require custom content structure can be omitted, especially those related to "sidebar modules";

Common Template Files for Pages

Template FileDescription
header.phpCommon header file
footer.phpCommon footer file

Templates Related to Homepage and List Pages

Template FileDescription
index.phpMain template file for homepage and list pages
post-multi.phpExcerpt article template
post-istop.phpSticky article template
pagebar.phpPage number template

Log/Standalone Page Related Templates

post-single.php

Template FileDescription
single.phpMain template file for article pages (single page)
Log page article template
post-page.phpStandalone page template
comments.phpComment section template
comment.phpTemplate for displaying each comment
commentpost.phpTemplate for comment submission form
commentpost-verify.phpComment verification code template (added in 1.5)

Sidebar Module Related Templates

  • Module display outer frame template

Template FileDescription
sidebar.phpDefault sidebar template, custom sidebar2.php to sidebar9.php can be used for subsequent sidebar calls
module.phpModule display template, can define module title format, etc. The specific content format of the module is determined by the detail templates below
  • Module content detail templates (version 1.5 and above)

Template FileDescriptionRemarks (Default number of lines)
module-archives.phpArchive moduleNo limit
module-authors.phpAuthor list moduleNo limit
module-calendar.phpCalendar moduleNo limit
module-catalog.phpCategory list moduleNo limit
module-navbar.phpNavigation bar moduleNo limit
module-statistics.phpSite information moduleNo limit
module-comments.phpRecent comments list module10 comments
module-previous.phpRecent posts list module10 posts
module-tags.phpTag list module25 tags

Writing Templates

Description Information (Optional)

  • Comment syntax within templates (recommended)

    Place on the first line of the template file:

    {* Template Name: "Description of template usage" *}

    Template type can also be declared (for "Main Entry Templates"):

    {* Template Name: Homepage and list page * Template Type: index|list *}

    Note: The necessity of "description information" and "type declaration" is only reflected in the option output when multiple "entry templates" are available for users to choose from for the same "page type", or when different template files are created for different "page types". For the latter, you need to implement conditional calls yourself or guide users to select settings.

    Important: Within the {}, there must be a space between the * and other content;

    - index           Homepage
    - list            List page
      - author
      - category
      - date
      - tag
    - single          Single page (including articles and pages)
      - article
      - page
    - search          Search
    - 404             404
    - none            Display hidden settings
  • Since version 1.7.0, template.json configuration is supported

    template.json example: (Click to expand)
    {
        "id": "Theme ID",
        "templates": [
            {
                "filename": "index",
                "type": "list",
                "name": "Auto template for list page"
            },
            {
                "filename": "single",
                "type": "single",
                "name": "Auto template for article/single page"
            }
        ]
    }

Embedded Calls

  • Embed template files

    {template:hearder} - Embeds the file content of the template file hearder.php.

    • "Embedded Call Example"

  • Embed module content

    {module:navbar} - Embeds the "Navigation Bar" module.

    Note: Except for "File Modules" in the include folder, other modules are actually stored in the database. Also, it is not recommended to use "File Modules" as user modifications will be overwritten during theme updates.

    • "Modules", or "Sidebar Modules", generally refer to the items listed in "Backend Management" → Module Management;

    • navbar is the "filename" of the "Navigation Bar" module, and other "modules" are similar;

Template Tags

In the "Template File Example", two syntax tags, {$language} and {$type}, are used, called "Variable Output Tags" or "Template Tags". They are actually compiled into <?php echo $language;?> and <?php echo $type;?> to output the corresponding variable values;

In Z-BlogPHP templates, you can use {$var} and {$obj.a} to output "variables or object properties of text or numeric type". The latter is compiled into <?php echo $obj->a;?>;

Note:

  1. Some tags can only be used on specific page types ($type values) or in certain contexts;

  2. {module:navbar} can be considered a shorthand for {$modules["navbar"].Content};

  3. In addition to system tags, variables output as tags can be customized or modified through the "interface mechanism" or "native PHP syntax ①";

Using PHP in Templates

Before outputting corresponding content, you can use the following syntax to further process the data;

{php}
// Native PHP can be written here;
$myVar = "Variable value";
{/php}
<p>Output a custom variable: {$myVar}</p>
<p>The current Z-BlogPHP version is: {$version}</p>

//You can also use <?php ?> symbols within {php}{/php} for code highlighting
{php}<?php

//Native php code

?>{/php}


Helpful?

Comments(1)

剑影无痕
剑影无痕

2025-10-09 14:07:45

全面解析了Z-BlogPHP主题的文件结构和模板编写规范。

Post comment

Support Live Chat
TOP