WordPress_php 팁에서 페이지 링크 및 제목을 얻기 위한 관련 PHP 함수의 사용 분석
get_permalink()(기사 또는 페이지 링크 가져오기)
get_permalink()는 고정된 링크를 기반으로 기사나 페이지의 링크를 반환하는 데 사용됩니다. 링크를 가져올 때 get_permalink() 함수는 가져올 기사의 ID를 알아야 합니다. 루프에 있는 경우 자동으로 현재 기사가 기본값이 됩니다.
사용방법
get_permalink( $id, $leavename );
매개변수
$id
(혼합) (선택 사항) 게시물 또는 페이지의 ID(정수)도 게시물 개체일 수 있습니다.
기본값: 루프에서 현재 기사를 자동으로 호출
$leavename
(부울) (선택 사항) 링크로 변환할 때 기사 별칭을 무시할지 여부입니다. True로 설정하면 http://www.example.com/my-post-name
대신 http://www.example.com/%postname%이 반환됩니다.기본값: 없음
반환값
(문자열 | 부울) 링크가 성공적으로 획득되면 링크를 반환하고, 그렇지 않으면 False를 반환합니다.
예
ID를 기반으로 기사나 페이지 링크 가져오기:
<a href="<?php echo get_permalink( 268 ); ?>">获取指定 ID 的文章或页面链接</a>
루프에서 현재 기사의 링크 가져오기:
<?php echo get_permalink(); ?>
페이지 제목을 기준으로 페이지 링크 가져오기:
<a href="<?php echo esc_url( get_permalink( get_page_by_title( '留言板' ) ) ); ?>">留言板</a>
기타
이 기능은 wp-includes/link-template.php에 있습니다
wp_title() (웹페이지 제목 가져오기)
wp_title()은 제목 태그의 내용인 현재 웹페이지의 제목을 가져오는 데 사용됩니다.
wp_title()은 다양한 페이지에 다양한 제목을 자동으로 생성할 수 있습니다. 예를 들어 홈페이지는 웹사이트 제목이고 기사 페이지는 기사 제목입니다. 모든 공식 워드프레스 테마에서는 이 기능을 사용하여 제목을 생성하지만, 국내 테마에서는 항상 무시됩니다(이 기능은 기본적으로 SEO에 별로 좋지 않기 때문입니다).
테마 개발 사양에 더 부합하는 제목 호출에 이 기능을 사용하는 것이 좋습니다. SEO에 더 부합하도록 하려면 필터를 사용하여 최적화할 수 있습니다. 이 기사의 끝.
사용방법
wp_title( $sep, $display, $seplocation );
매개변수
$9월
(문자열) (선택 사항) 제목 내용의 구분 기호로, 일반적으로 "|" 또는 "-"로 설정됩니다.
기본값: »(»)
$디스플레이
(Boolean) (선택) 제목을 직접 출력할지 여부. False로 설정하면 제목이 반환되어 변수에 저장될 수 있습니다.
기본값: True(직접 인쇄)
$seplocation
(문자열) (선택 사항) 구분 기호의 위치는 왼쪽 또는 오른쪽입니다. "right"가 전달되면 오른쪽이 되고 다른 모든 항목은 왼쪽이 됩니다.
기본값: 빈 문자열(왼쪽)
반환값
(문자열) $display 매개변수를 False로 설정하면 제목의 내용이 반환될 수 있습니다. 기본적으로 반환되는 내용은 다음과 같습니다.
- 기사 페이지: 기사 제목
- 날짜 페이지: 날짜
- 카테고리 페이지: 카테고리 제목
- 작가 페이지: 작가 이름
/** * 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 $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 post type archive if ( is_post_type_archive() ) { $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) $post_type = reset( $post_type ); $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object->has_archive ) $title = post_type_archive_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(); if ( $term ) { $tax = get_taxonomy( $term->taxonomy ); $title = single_term_title( $tax->labels->name . $t_sep, false ); } } // If there's an author if ( is_author() && ! is_post_type_archive() ) { $author = get_queried_object(); if ( $author ) $title = $author->display_name; } // Post type archives with has_archive should override terms. if ( is_post_type_archive() && $post_type_object->has_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 "; /** * Filter the parts of the page title. * * @since 4.0.0 * * @param array $title_array Parts of the page title. */ $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); // Determines position of the separator and direction of the breadcrumb if ( 'right' == $seplocation ) { // sep on right, so reverse the order $title_array = array_reverse( $title_array ); $title = implode( " $sep ", $title_array ) . $prefix; } else { $title = $prefix . implode( " $sep ", $title_array ); } /** * Filter the text of the page title. * * @since 2.0.0 * * @param string $title Page title. * @param string $sep Title separator. * @param string $seplocation Location of the separator (left or right). */ $title = apply_filters( 'wp_title', $title, $sep, $seplocation ); // Send it out if ( $display ) echo $title; else return $title; }
예
<title><?php wp_title( '|', true, 'right' ); ?></title>
제목은 wp_title 필터를 사용하여 맞춤 설정할 수 있습니다. 이 기능은 wp-includes/general-template.php에 있습니다.

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

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

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

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

뜨거운 주제











이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는
