Summary of commonly used functions and methods in WordPress
The main reason for choosing to use WordPress to build a blog is that WordPress has a high popularity, and there are all kinds of extension functions developed around it. Basically, it can be said that any function we need in blog construction , someone has thought of it and implemented it, so that you don’t have to invest too much energy in the specific technical implementation and functional expansion of your blog, but focus more on content construction.
This article briefly summarizes the basic information of WordPress theme templates in the form of a technical manual, hoping to quench the thirst of friends who develop WordPress theme templates.
WordPress theme template basic files
A complete set of WordPress theme templates should have at least the following files:, WordPress basic template files, WordPress template essential files:
style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : Archive/Category模板 404.php : Not Found 错误页模板 comments.php : 留言/回复模板 footer.php : Footer模板 header.php : Header模板 sidebar.php : 侧栏模板 page.php : 内容页(Page)模板 single.php : 内容页(Post)模板 searchform.php : 搜索表单模板 search.php : 搜索结果模板
Basic condition judgment Tag
is_home() : 是否为主页 is_single() : 是否为内容页(Post) is_page() : 是否为内容页(Page) is_category() : 是否为Category/Archive页 is_tag() : 是否为Tag存档页 s_date() : 是否为指定日期存档页 is_year() : 是否为指定年份存档页 is_month() : 是否为指定月份存档页 is_day() : 是否为指定日存档页 is_time() : 是否为指定时间存档页 is_archive() : 是否为存档页 is_search() : 是否为搜索结果页 s_404() : 是否为 “HTTP 404: Not Found” 错误页 is_paged() : 主页/Category/Archive页是否以多页显示
PHP functions commonly used in the Header part
<?php bloginfo (’name’); ?> : 博客名称(Title) <?php bloginfo (’stylesheet_url’); ?> : CSS文件路径 <?php bloginfo (’pingback_url’); ?> : PingBack Url <?php bloginfo (’template_url’); ?> : 模板文件路径 <?php bloginfo (’version’); ?> : WordPress版本 <?php bloginfo (’atom_url’); ?> : Atom Url <?php bloginfo (’rss2_url’); ?> : RSS 2.o Url <?php bloginfo (’url’); ?> : 博客 Url <?php bloginfo (’html_type’); ?> : 博客网页Html类型 <?php bloginfo (’charset’); ?> : 博客网页编码 <?php bloginfo (’description’); ?> : 博客描述 <?php wp_title(); ?> : 特定内容页(Post/Page)的标题
PHP functions commonly used in templates And the command
<?php get_header(); ?> : 调用Header模板 <?php get_sidebar(); ?> : 调用Sidebar模板 <?php get_footer(); ?> : 调用Footer模板 <?php the_content(); ?> : 显示内容(Post/Page) <?php the_excerpt(); ?>: 显示摘要 <?php if (have_posts()) : ?> : 检查是否存在Post/Page <?php while (have_posts()) : the_post(); ?> : 如果存在Post/Page则予以显示 <?php endwhile ; ?> : While 结束 <?php endif ; ?> : If 结束 <?php the_time(’字符串’) ?> : 显示时间,时间格式由“字符串”参数决定,具体参考PHP手册 <?php comments_popup_link(); ?> : 正文中的留言链接。如果使用 comments_popup_script() ,则留言会在新窗口中打开,反之,则在当前窗口打开 <?php the_title(); ?> : 内容页(Post/Page)标题 <?php the_permalink() ?> : 内容页(Post/Page) Url <?php the_category(’, ‘) ?> : 特定内容页(Post/Page)所属Category <?php the_author(); ?> : 作者 <?php the_ID(); ?> : 特定内容页(Post/Page) ID <?php edit_post_link(); ?> : 如果用户已登录并具有权限,显示编辑链接 <?php get_links_list(); ?> : 显示Blogroll中的链接 <?php comments_template(); ?> : 调用留言/回复模板 <?php wp_list_pages(); ?> : 显示Page列表 <?php wp_list_categories(); ?> : 显示Categories列表 <?php next_post_link(’ %link ‘); ?> : 下一篇文章链接 <?php previous_post_link(’%link’); ?> : 上一篇文章链接 <?php get_calendar(); ?> : 日历 <?php wp_get_archives() ?> : 显示内容存档 <?php posts_nav_link(); ?> : 导航,显示上一篇/下一篇文章链接 <?php include (TEMPLATEPATH . ‘/文件名’); ?> : 嵌入其他文件,可为定制的模板或其他类型文件
Other functions related to the template
<?php _e(’Message’); ?> : 输出相应信息 <?php wp_register(); ?> : 显示注册链接 <?php wp_loginout(); ?> : 显示登录/注销链接 <–next page–> : 将当前内容分页 <–more–> : 将当前内容截断,以不在主页/目录页显示全部内容 <?php timer_stop(1); ?> : 网页加载时间(秒) <?php echo get_num_queries(); ?> : 网页加载查询量
Others
<?php get_archives(’postbypost’, 10); ?> 调用最近的10篇日志 <?php $rand_posts = get_posts(’numberposts=10&orderby=rand’); foreach ( $rand_posts as $post ) : ?> <li><a href= "”<?php" the_permalink();= "" ?= "" >”> <?php the_title(); ?></a></li> <?php endforeach ; ?>
Randomly call 10 logs
<?php the_tags(’Post Tags :’, ‘, ‘, ‘<br />’); ?> 调用标签 <?php if (get_the_tags()) the_tags(’Tags:’,’,’,’ end ’); ?>
Called when the tag exists
<?php wp_tag_cloud(’smallest=1&largest=9&’); ?> 调用标签云 <?php $posts = get_posts( “category=12&numberposts=4″ ); ?> 获得4篇12分类中的日志
Let’s have some more detailed judgment functions
<?php if (is_single()):?> //这里写你想显示的内容,包括函数 <?php endif ;?>
The following is the direct From wordpress.org
is_single() 判断是否是具体文章的页面 is_single(’17′) 判断是否是具体文章(id=17)的页面 is_single(’Beef Stew’) 判断是否是具体文章(标题判断)的页面 is_single(’beef-stew’) 判断是否是具体文章(slug判断)的页面 comments_open() 是否留言开启 pings_open() 是否开启ping is_page() 是否是页面 is_page(’42′) 同single,id判断,即是否是id为42的页面 is_page(’About Me’) title判断 is_page(’about-me’) slug判断 is_category() 是否是分类 is_category(’6′) 同single,id判断,即是否是id为6的分类 is_category(’Cheeses’) title判断 is_category(’cheeses’) slug判断 in_category(’5′) 判断当前的文章是否属于分类5 is_author() 将所有的作者的页面显示出来 is_author(’1337′) 显示author number为1337的页面 is_author(’Elite Hacker’) 通过昵称来显示当前作者的页面 is_author(’elite-hacker’) is_date() is_year() is_month() is_day() is_time() is_archive() 判断当前是否是归档页面 is_search() 判断是否是搜索 is_404() 判断页面是否404 is_paged() 判断是否翻页,比如你当前的blog是http: //domain.com,显示http: //domain.com?paged=2的时候,这个判断将返回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界面,例如: if (is_home() && !is_paged()
The above is the detailed content of Summary of commonly used functions and methods in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use <?php comments_template(); ?> tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to
