Complete WordPress template making tutorial, WordPress new page template

1 year ago (2023-12-01) Chief Editor
10 minutes
three hundred and thirty-six
zero

A complete set of WordPress templates should at least have the following documents:

·Style.css: CSS (style sheet) file

·Index.php: Home page template

·Archive.php: Archive/Category template

·404.php: Not Found error page template

·Comments. php: message/reply template

·Footer.php: Footer template

·Header.php: Header template

·Sidebar.php: sidebar template

·Page.php: Content page (Page) template

·Single.php: content page (Post) template

·Searchform.php: search form template

·Search.php: search results template

Of course, there may be more than these files for a specific template, but generally speaking, these files are necessary for each set of templates.

Basic condition judgment Tag

·Is_home(): Whether it is the home page

·Is_single(): Whether it is a content page (Post)

·Is_page(): Is it a content page

·Is_category(): Whether it is a Category/Archive page

·Is_tag(): Whether it is a Tag archive page

·Is_date(): Whether to archive the page for the specified date

·Is_year(): Whether to archive the page for the specified year

·Is_month(): Whether to archive the page for the specified month

·Is_day(): Whether it is the archive page of the specified day

·Is_time(): Whether to archive the page for the specified time

·Is_archive(): Whether it is an archive page

·Is_search(): Whether it is a search result page

·Is_404(): Is it an "HTTP 404: Not Found" error page

·Is_paged(): Whether the home page/Category/Archive page is displayed in multiple pages

Commonly used PHP functions in Header

· <? php bloginfo(’name’); ?> : Blog name (Title)

· <? php bloginfo(’stylesheet_url’); ?> : CSS file path

· <? php bloginfo(’pingback_url’); ?> : PingBack Url

· <? php bloginfo(’template_url’); ?> : Template file path

· <? php bloginfo(’version’); ?> : WordPress version

· <? php bloginfo(’atom_url’); ?> : Atom Url

· <? php bloginfo(’rss2_url’); ?> : RSS 2.o Url

· <? php bloginfo(’url’); ?> : Blog Url

· <? php bloginfo(’html_type’); ?> : Blog Page Html Type

· <? php bloginfo(’charset’); ?> : Blog Page Encoding

· <? php bloginfo(’description’); ?> : Blog Description

· <? php wp_title(); ?> : Title of the specific content page (Post/Page)

PHP functions and commands commonly used in templates

· <? php get_header(); ?> : Call Header Template

· <? php get_sidebar(); ?> : Call Sidebar template

· <? php get_footer(); ?> : Call Footer template

· <? php the_content(); ?> : Display content (Post/Page)

· <? php if(have_posts()) : ?> : Check whether Post/Page exists

· <? php while(have_posts()) : the_post(); ?> : Display if Post/Page exists

· <? php endwhile; ?> : While End

· <? php endif; ?> : If End

· <? Php the_time ('string ')?> : Display time. The time format is determined by the "string" parameter. Please refer to PHP Manual

· <? php comments_popup_link(); ?> : The message link in the body. If comments_popup_script() is used, the message will be opened in a new window; otherwise, it will be opened in the current window

· <? php the_title(); ?> : Content page (Post/Page) title

· <? php the_permalink() ?> : Content Page (Post/Page) Url

· <? php the_category(’, ‘) ?> : Category of the specific content page (Post/Page)

· <? php the_author(); ?> : Author

· <? php the_ID(); ?> : Specific content page (Post/Page) ID

· <? php edit_post_link(); ?> : If the user is logged in and has permission, display the edit link

· <? php get_links_list(); ?> : Show links in Blogroll

· <? php comments_template(); ?> : Call message/reply template

· <? php wp_list_pages(); ?> : Display Page List

· <? php wp_list_categories(); ?> : Show Categories list

· <? php next_post_link(’ %link ‘); ?> : Next article link

· <? php previous_post_link(’%link’); ?> : Link to previous article

· <? php get_calendar(); ?> : Calendar

· <? php wp_get_archives() ?> : Show Content Archive

· <? php posts_nav_link(); ?> : Navigation, showing previous/next article links

· <? Php include (TEMPLATEPATH. '/filename');?> : Embed other files, which can be customized templates or other types of files

Other functions related to templates

· <? php _e(’Message’); ?> : Output corresponding information

· <? php wp_register(); ?> : Show registration link

· <? php wp_loginout(); ?> : Show login/logout link

· <!– next page–> : Page the current content

· <!– more–> : Truncate the current content so that all content is not displayed on the home page/directory page

· <? php timer_stop(1); ?> : Page load time (seconds)

· <? php echo get_num_queries(); ?> : Page load queries

In this section, we will continue to introduce how to define index.php and how to derive other files. In the index.php file, in the body element, create the following structural markup elements with different id attributes:

</div>

These different attributes represent different regions, which can be seen at a glance. Next, we will focus on the construction of header, content, sidebar and footer.

(1) . Build header

Enter the following code between the two tags of the<div id="header"></div>element:

” title=” ”>

<p><? php bloginfo(’description’); ?></ p>

Here we use WP's built-in bloginfo function to generate content, where:

Bloginfo ('url ') returns to the homepage link of the website;

Bloginfo ('name ') returns the website title;

Bloginfo ('description ') returns the website description.

Save the index.php file, and then press F5 in the browser to refresh the page. What can you see? Then check the relevant information generated by WP's bloginfo () function through "View Source File".

(2) . Build content

stay

In, we want to display blog posts by looping, including the title, author, publication date and other relevant information of each blog post. In addition, the blog can be displayed in pages (depending on the setting of the WP background). First, enter the following code between<div id="content">and</div>:

”>

” rel=”bookmark” title=” ”>

</div><? php endif; ?>

It seems complicated, but it is not. first:

<? php endwhile; ?>

These two lines are the while loop in WP. The while statement determines whether to call the_post() function by testing have_posts(). If the test have_posts() returns true, the the_post() function is called to initialize the built-in variables related to blog posts.

In the while loop, first of all, pay attention to the nested semantic structure defined by the div, h2, and span elements, as well as the class and id attributes of the corresponding elements (only the div element whose class is post defines an id attribute post -<? Php the_ID()?>). This is the key to using CSS to control appearance in the future. In this div element, the following WP functions are called respectively to display relevant information of blog posts:

The_ID(): returns the blog ID;

The_permalink(): returns the blog fixed link URL;

The_title(): returns the blog title;

The_time ('M '): returns the month in the publication date;

The_time ('d '): returns the days in the publication date;

The_author(): returns the blog author;

The_category(): returns the category of blog posts;

The_content(): returns the content of the blog, in which the parameter represents the link text for "more content";

The above functions all start with the_, and the function names after them are not only self explanatory, but also reminiscent of this keyword. in addition

_The e() function is a wrapper function, which is mainly used for language conversion. If this function is called and standard WP terms are passed, such as Author or Categories, then the translation in your corresponding language package will be returned. In the Chinese language package, it is "Author" and "Category" respectively. Of course, no need. But it will lose some adaptability.

In addition, the comments_popup_link() and edit_post_link() functions display comments and edit links, which will not be covered here.

In addition, in the The paging navigation link is shown later. The functions called are: next_posts_link() and previous_posts_link(). At this time, if the total number of your blog posts is less than the maximum number of posts set to be displayed in the WP background, for example, if you set a maximum of 5 posts to be displayed in the background, and you have 10 blog posts, they will be displayed in pages; Otherwise, if your blog posts are less than or equal to 5, you will not see paging navigation links.

Finally, don't leave<? php else : ?> What follows the statement:

</div>

Obviously, this is an error message.

(3) . Build sidebar

Of course, the content of the sidebar should be

Element. Sidebar, which is called sidebar in Chinese, can contain many contents. For example, navigation and related information such as categories, pages, links, calendars, etc. In WP, the contents in the sidebar are output in the form of unordered (ul) or ordered (ol) lists. Therefore, you need to enter the following tags in<div id="sidebar"></div>:

Page);?>

’, ‘’, ‘’, FALSE, ‘id’, FALSE, FALSE, -1, FALSE); ?>

</ul>The above code starts from the third line and displays the search form by including searchform.php;

Call the get_calendar() function to display the calendar;

Call the wp_list_pages() function to display the page navigation;

Call the wp_list_cats() function to display the classification navigation;

Call the wp_get_archives() function to display archive navigation;

Call the get_links() function to display the link navigation.

When building the sidebar, you need to create a searchform.php file for generating the search box. Its contents are as follows:

/”>

” name=”s” id=”s” size=”15″ />

</form>

Save it in the myTheme folder and include it with the include statement. Note that the template path is saved in the constant TEMPLATEPATH.

Finally, explain the second line and the penultimate line of the above code. Obviously, this is an if statement block. What is the purpose of this if statement block containing sidebar? This is the need to make the sidebar suitable for Widget plug-ins (Widgets are built in after WP 2.0, so you don't need to install them again). If you want to use the Widget plug-in, you must component the sidebar. In this way, you can use drag to easily define the components of the sidebar through the Widget plug-in in the WP background. In addition to putting the if statement inside the ul element in the partial sidebar, you must also create a file functions.php in the myTheme folder. Its contents are as follows:

if ( function_exists(’register_sidebar’) )

register_sidebar(array(

‘before_widget’ => ‘

  • ’,
  • ‘after_widget’ => ‘’,

    ‘before_title’ => ‘

    ’,

    ‘after_title’ => ‘’,

    ));

    ?>

    (4) . Component footer

    Generally, there are some copyright information and less important links in footer. So you can simply put the following code in the<div id="footer"></div>element:

    <p>Copyright ? 2007 <? php bloginfo(’name’); ?></ p>

    At this point, the core index.php file is complete!

    Next, split index.php and generate sub template files based on index.php.

    Create three new files in the myTheme folder: header.php, sidebar.php, and footer.php. Transfer (cut) the three structural elements and their contents of<div id="header"></div>,<div id="sidebar"></div>and<div id="footer"></div>in index.php to these three new files. Then, enter the code in the original location:

    <? php get_header();?>

    Enter the code in the original location of<div id="sidebar"></div>:

    <? php get_sidebar();?>

    Enter the code in the original location:

    <? php get_footer();?>

    As mentioned earlier, these three get functions are specifically defined by WP for structured files. Now your index.php file should be as follows:

    ; charset= ” /> Complete WordPress template making tutorial, WordPress new page template - little turkey software development - 上海千花后花园-上海各区gm资源汇总-夜上海社区论坛-爱上海后花园 ” /> ” type=”text/css” media=”all” />

    /print.css” type=”text/css” media=”print” />

    RSS Feed” href=” ” />

    ” />

    ”>

    ” rel=”bookmark” title=” ”>

    </html>

    Then, it generates sub template files. Save the "modular" index.php file as single.php, page.php, archive.php, search.php, and category.php. Of course, they are saved in the myTheme folder. In this way, WP will call the corresponding page file when displaying the page. For example, when the blog details are displayed, single.php will be called; When the page content is displayed, page.php is called.

    Finally, you need to customize these sub template files.

    This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/1317.html
    Kuke_WP editor
    author

    Related recommendations

    1 year ago (2024-02-20)

    What are the main contents of wms system in warehouse management

    Original title: What does the wms system mainly embody in warehouse management? What does the wms system mainly embody in warehouse management? Warehouse management has standardized and intelligent process oriented management. A good warehouse management mechanism can improve the efficiency of warehouse managers, relieve their pressure, and complete efficient and accurate work. 1. Warehouse management is accompanied by the progress of the times
    1 year ago (2024-02-18)

    How to implement the mptt comment function of CMS content management system in Django?, Django management page

    During the daily development of content related Web systems in the directory, whether it is Blog or CMS, if you need to add links to interact with users, you must need the comment function. Next, you can implement the comment reply function in Django based on Python's MPTT framework. Note: Because the user comment function will involve a
    three hundred and ninety-four
    zero
    1 year ago (2024-02-18)

    Best CMS content management system in 2022, good novel in 2021

    Looking for the best CMS software to build your website? At a high level, CMS or content management systems can help you create functional websites without having to use code to build every page from scratch. However, different CMS software has different advantages and disadvantages, so you need to choose the tool that best suits your specific needs and budget. To help, we accept
    four hundred and six
    zero
    1 year ago (2024-02-18)

    Shenzhen promotes the access of 5G base station energy storage system to the virtual power plant management center in the city. Does the Shenzhen 5g government subsidize the flow package charge

    Xinhua News Agency, Shenzhen, December 14 (Reporter Wang Feng) At the 2022 Carbon Peak Carbon Neutralization Forum and Shenzhen International Low Carbon City Forum held here in Shenzhen, Shenzhen Virtual Power Plant Management Center signed a cooperation agreement on virtual power plant construction with China Tower, China Telecom, China Mobile, China Unicom, Huawei Digital Energy and other units on the 13th, which will jointly promote the city's 5G base station energy storage system
    three hundred and forty-three
    zero
    1 year ago (2024-02-18)

    Common website cms content management system recommendation, common website cms content management software

    CMS is the abbreviation of "Content Management System", which means "Content Management System" in Chinese. These systems have developed common website functions and provided them to users for download, greatly improving the efficiency of website construction. The most common functions of CMS are column management, article management, product management, picture management
    three hundred and twenty-eight
    zero

    comment

    0 people have participated in the review

    Scan code to add WeChat

    contact us

    WeChat: Kuzhuti
    Online consultation: