워드프레스의 wp_title 함수는 기사 제목, 페이지, 카테고리 등을 표시하는 데 사용되는 함수이지만, 홈페이지 색인에서는 이 함수가 아무것도 표시하지 않습니다. 이 기능은 항상 공식 WordPress 테마에서 사용되었지만 많은 사용자 정의 테마에서는 항상 무시됩니다.
함수 의미에 대한 자세한 설명
wp_title 함수는 페이지 제목을 표시하는 데 사용됩니다. 예를 들어 기사 페이지에서는 기사 제목이 표시되고, 카테고리 이름은 홈페이지 색인에 표시됩니다. 아무것도 표시하지 않습니다.
이는 WordPress의 get_the_title 및 Single_cat_title() 두 함수를 적응적으로 사용하는 것과 약간 비슷합니다(페이지, 기사, 카테고리, 아카이브 또는 태그인지 자동으로 확인).
함수 선언
좀 긴 글이니 한 번이라도 인내심을 갖고 읽어주시길 바랍니다.
/** * Display or retrieve page title for all areas of blog. * * By default, the page title will display the separator before the page title, * so that the blog title will be before the page title. This is not good for * title display, since the blog title shows up on most tabs and not what is * important, which is the page that the user is looking at. * * There are also SEO benefits to having the blog title after or to the 'right' * or the page title. However, it is mostly common sense to have the blog title * to the right with most browsers supporting tabs. You can achieve this by * using the seplocation parameter and setting the value to 'right'. This change * was introduced around 2.5.0, in case backwards compatibility of themes is * important. * * @since 1.0.0 * * @param string $sep Optional, default is '»'. How to separate the various items within the page title. * @param bool $display Optional, default is true. Whether to display or retrieve title. * @param string $seplocation Optional. Direction to display title, 'right'. * @return string|null String on retrieve, null when displaying. */ function wp_title($sep = '»', $display = true, $seplocation = '') { global $wpdb, $wp_locale; $m = get_query_var('m'); $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); $day = get_query_var('day'); $search = get_query_var('s'); $title = ''; $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary // If there is a post if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) { $title = single_post_title( '', false ); } // If there's a category or tag if ( is_category() || is_tag() ) { $title = single_term_title( '', false ); } // If there's a taxonomy if ( is_tax() ) { $term = get_queried_object(); $tax = get_taxonomy( $term->taxonomy ); $title = single_term_title( $tax->labels->name . $t_sep, false ); } // If there's an author if ( is_author() ) { $author = get_queried_object(); $title = $author->display_name; } // If there's a post type archive if ( is_post_type_archive() ) $title = post_type_archive_title( '', false ); // If there's a month if ( is_archive() && !empty($m) ) { $my_year = substr($m, 0, 4); $my_month = $wp_locale->get_month(substr($m, 4, 2)); $my_day = intval(substr($m, 6, 2)); $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' ); } // If there's a year if ( is_archive() && !empty($year) ) { $title = $year; if ( !empty($monthnum) ) $title .= $t_sep . $wp_locale->get_month($monthnum); if ( !empty($day) ) $title .= $t_sep . zeroise($day, 2); } // If it's a search if ( is_search() ) { /* translators: 1: separator, 2: search phrase */ $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search)); } // If it's a 404 page if ( is_404() ) { $title = __('Page not found'); } $prefix = ''; if ( !empty($title) ) $prefix = " $sep "; // Determines position of the separator and direction of the breadcrumb if ( 'right' == $seplocation ) { // sep on right, so reverse the order $title_array = explode( $t_sep, $title ); $title_array = array_reverse( $title_array ); $title = implode( " $sep ", $title_array ) . $prefix; } else { $title_array = explode( $t_sep, $title ); $title = $prefix . implode( " $sep ", $title_array ); } $title = apply_filters('wp_title', $title, $sep, $seplocation); // Send it out if ( $display ) echo $title; else return $title; }
사용방법
<?php wp_title( $sep, $echo, $seplocation ); ?>
매개변수 상세 설명
- $sep: 구분 기호
- $echo: 표시 여부
- $seplocation : 구분 기호 위치(왼쪽 또는 오른쪽, '오른쪽'만 허용, 오른쪽이 아닌 경우 자동으로 왼쪽으로 판단)
요약
WordPress에는 동일한 기능을 가진 많은 기능이 있으며 기본 수준에서 고급 수준까지 캡슐화되어 최종적으로 사용 계층에 도달합니다. 물론 유연한 사용법이 필요한 경우에는 해당 기능을 직접 사용할 수 있습니다. 중간 레이어. 그렇다면 wp_title 함수와 같은 가장 고급 함수 레이어를 직접 사용할 수 있습니다. 실제로 wp는 다양한 유형의 페이지에서 이 함수를 수행합니다. 카테고리, 태그, 기사, 아카이브, 저자, 페이지 등과 같은 목적을 달성하기 위해 다양한 페이지에 따라 다양한 제목 기능을 판단하고 호출합니다.
시간이 되시면 다음 기능들에 대해 심도있게 공부하시고 SEO를 좀 더 유연하게 수행하실 수 있습니다
기사 페이지에서 제목을 추출하는 Single_post_title 함수
Single_term_title 태그(태그), cat(카테고리), 날짜, Single_cat_title() 함수와 유사한 제목 추출 함수
get_queried_object 작성자 페이지에서 개체를 추출하는 함수(개체에는 작성자 이름이 있음)
post_type_archive_title() 파일과 제목을 추출하는 기타 기능
당신은 무엇을 기다리고 있습니까?
GO GO GO!

wordpress标签错误的解决办法:1、找到并打开wordpress的“wp-includes”目录下的“class-wp.php”文件;2、修改内容为“$pathinfo = isset( $_SERVER['PATH_INFO'] )?mb_convert_encoding($_SERVER['PATH_INFO'],'utf-8','GBK') : '';”即可。

wordpress后台乱码的解决办法:1、在wordpress的“wp-admin”文件夹下找到“admin.header.php”文件;2、将“charset”属性值设置为“UTF-8”格式即可恢复正常。

你下载的WordPress主题提供的keywords和description这两个meta标签一般都做得很差,或者根本就不提供,这样不利于SEO。本文将指导你如何给主页、分类、页面以及文章页添加单独的Description 和 Keywords。

wordpress乱码的解决办法:1、修改“wp-config.php”文件里的“define(’DB_CHARSET’, ‘utf8′);”为“define(’DB_CHARSET’, ”);”;2、把新数据库的编码设置成“latin1_swedish_ci”;3、以uft8的格式导入备份的数据库文件即可。

wordpress进不去的解决办法:1、把地址栏“wp-login.php”后面的参数删掉,然后重新输入密码登录;2、登录FTP,下载“pluggable.php”文件,然后找到“ADMIN_COOKIE_PATH”并将它替换为“SITECOOKIEPATH”即可。

wordpress不是saas。SaaS是一种软件销售模式,它主要针对云端应用软件,而WordPress是一款CMS系统,它主要针对网站构建和管理。虽然WordPress可以作为SaaS提供服务,但它本质上不是一种SaaS应用。

wordpress是2003年发布的;Matt于2003年5月27日宣布推出第一版WordPress,受到了社区的欢迎,它基于b2 Cafelog并有显著改进;WordPress的第一个版本包括全新的管理界面、模板、XHTML 1.1兼容模板、内容编辑器。

本次PHP中文网整合了相关的视频教程,中文手册,以及相关的精选文章安利给大家,统统免费!!!通过我们分享的视频,可随时随地免费观看教程视频,也不需要迅雷或者百度网盘下载了。


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

Dreamweaver Mac版
시각적 웹 개발 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.
