WordPress开发中用于标题显示的相关函数使用解析_PHP
single_cat_title()函数
single_cat_title()函数,日常中我们很少会用到,但这个函数会给我们解决很多问题,诸如当前页面的目录、标签,该函数不依附于 WordPress 主循环中,也不能放入主循环中使用。
描述
获取当前页面的分类、标签。
<?php single_cat_title($prefix,$display); ?>
- $prefix :用于设置在标题之前显示的内容。
- $display :用于设置是直接显示还是返回到变量。
实例
在此摘取 WordPress 2011 默认主题中,category.php 文件 第18行左右位置的代码
<?php printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?>
get_the_title 和 the_title
get_the_title 和 the_title 两个函数用来在文章页面显示文章标题的函数,之所以将两个函数合并到一篇文章里面去是因为这两个函是一个实现,只不过 the_title 默认直接显示,get_the_title 默认返回字符串,如果你对此心存疑惑,那请你往下看。
函数详解
get_the_title 和 the_title这两个函数主要用于在循环中显示当前文章的标题,请注意 the_title 这个函数必须使用在循环中。
两者的区别在于,get_the_title仅能以字符串形式返回文章标题,而 the_title 可以设置标题前后的自定义字符,以及是显示还是返回字符串。
the_title 函数使用、参数详解
<?php the_title( $before, $after, $echo ); ?>
- $before标题前的字符
- $after标题后的字符
- $echo显示、还是返回字符串,默认为true
the_title示例
<?php the_title( ‘=>', ‘<=' ); ?>
以本文为例,我们将得到以下这样的标题:
‘=>get_the_title 和 the_title<='
get_the_title 函数使用、参数详解
<?php $myTitle = get_the_title($ID); ?>
以上代码我们将得到文章标题的变量$myTitle;
$ID 用于设置文章 ID ,当然在循环中我们可以省略此参数。
get_the_title 示例
<?php $myTitle = get_the_title($ID); echo $mytitle.'【标题演示】'; ?>
我们将得到
get_the_title 和 the_title【标题演示】
总结
说了这么多,不知道对您是否有所帮助?
总的来说 the_title 是 get_the_title的更高一级封装。就像在 wp_title中说的那样,更高级封装,虽然使用起来简单,但能折腾花样相对少了点。
下面是该两个函数的源代码
the_title 函数声明
该函数位于 wp-include/post-template.php 文件的 43 – 55行左右的位置
<?php /** * Display or retrieve the current post title with optional content. * * @since 0.71 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to the title. * @param bool $echo Optional, default to true.Whether to display or return. * @return null|string Null on no title. String if $echo parameter is false. */ function the_title($before = '', $after = '', $echo = true) { $title = get_the_title(); if ( strlen($title) == 0 ) return; $title = $before . $title . $after; if ( $echo ) echo $title; else return $title; } ?>
get_the_title 函数声明
该函数位于 wp-include/post-template.php 文件的 103 – 118行左右的位置
<?php /** * Retrieve post title. * * If the post is protected and the visitor is not an admin, then "Protected" * will be displayed before the post title. If the post is private, then * "Private" will be located before the post title. * * @since 0.71 * * @param int $id Optional. Post ID. * @return string */ function get_the_title( $id = 0 ) { $post = &get_post($id); $title = isset($post->post_title) ? $post->post_title : ''; $id = isset($post->ID) ? $post->ID : (int) $id; if ( !is_admin() ) { if ( !empty($post->post_password) ) { $protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); $title = sprintf($protected_title_format, $title); } else if ( isset($post->post_status) && 'private' == $post->post_status ) { $private_title_format = apply_filters('private_title_format', __('Private: %s')); $title = sprintf($private_title_format, $title); } } return apply_filters( 'the_title', $title, $id ); } ?>

핫 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)

뜨거운 주제











PHP와 Flutter는 모바일 개발에 널리 사용되는 기술입니다. Flutter는 크로스 플랫폼 기능, 성능 및 사용자 인터페이스가 뛰어나며 고성능, 크로스 플랫폼 및 맞춤형 UI가 필요한 애플리케이션에 적합합니다. PHP는 성능이 낮고 크로스 플랫폼이 아닌 서버 측 애플리케이션에 적합합니다.

style.css 파일을 편집하여 WordPress 페이지 너비를 쉽게 수정할 수 있습니다. style.css 파일을 편집하고 .site-content { max-width: [원하는 너비] }를 추가하세요. [원하는 너비]를 편집하여 페이지 너비를 설정하세요. 변경 사항을 저장하고 캐시를 지웁니다(선택 사항).

WordPress에서 제품 페이지 만들기: 1. 제품 만들기(이름, 설명, 사진) 2. 페이지 템플릿 사용자 정의(제목, 설명, 사진, 버튼 추가) 3. 제품 정보(재고, 크기, 무게)를 입력합니다. 4. 변형(다양한 색상, 크기)을 만듭니다. 5. 공개 또는 숨김을 설정합니다. 6. 댓글을 활성화/비활성화합니다. 7. 페이지를 미리 보고 게시합니다.

WordPress 게시물은 /wp-content/uploads 폴더에 저장됩니다. 이 폴더는 하위 폴더를 사용하여 연도, 월, 기사 ID별로 정리된 기사를 포함하여 다양한 유형의 업로드를 분류합니다. 기사 파일은 일반 텍스트 형식(.txt)으로 저장되며 파일 이름에는 일반적으로 ID와 제목이 포함됩니다.

WordPress 템플릿 파일은 /wp-content/themes/[테마 이름]/ 디렉터리에 있습니다. 헤더(header.php), 바닥글(footer.php), 기본 템플릿(index.php), 단일 기사(single.php), 페이지(page.php)를 포함하여 웹사이트의 모양과 기능을 결정하는 데 사용됩니다. , 아카이브(archive.php), 카테고리(category.php), 태그(tag.php), 검색(search.php) 및 404 오류 페이지(404.php). 이러한 파일을 편집하고 수정하면 WordPress 웹사이트의 모양을 사용자 정의할 수 있습니다.

WordPress에서 작성자 검색: 1. 관리자 패널에 로그인한 후 게시물 또는 페이지로 이동하여 검색 표시줄을 사용하여 작성자 이름을 입력하고 필터에서 작성자를 선택합니다. 2. 기타 팁: 와일드카드를 사용하여 검색 범위를 넓히고, 연산자를 사용하여 기준을 결합하거나, 저자 ID를 입력하여 기사를 검색하세요.

가장 안정적인 WordPress 버전은 최신 보안 패치, 성능 향상, 새로운 기능 및 개선 사항이 포함된 최신 버전입니다. 최신 버전으로 업데이트하려면 WordPress 대시보드에 로그인하고 업데이트 페이지로 이동하여 지금 업데이트를 클릭하세요.

WordPress는 데이터베이스 상호 작용, 양식 처리, 동적 콘텐츠 생성 및 사용자 요청을 처리하기 위한 핵심 프로그래밍 언어로 PHP 언어를 사용하여 개발되었습니다. PHP는 크로스 플랫폼 호환성, 학습 용이성, 활발한 커뮤니티, 풍부한 라이브러리 및 프레임워크 등의 이유로 선택되었습니다. WordPress는 PHP 외에도 HTML, CSS, JavaScript, SQL 등과 같은 언어를 사용하여 기능을 향상시킵니다.
