get_query_var() - WordPress 函数参考中文文档

返回介绍

get_query_var()

发布于 2017-09-11 字数4374 浏览 742 评论 0

get_query_var( string $var,  mixed $default = '' )

Retrieve variable in the WP_Query class.


描述


参数

$var

(string)
(Required)
The variable key to retrieve.

$default

(mixed)
(Optional)
Value to return if the query variable is not set.

Default value: ”


返回值

(mixed) Contents of the query variable.


源代码

File: wp-includes/query.php

function get_query_var( $var, $default = '' ) {
	global $wp_query;
	return $wp_query->get( $var, $default );
}

更新日志

Version 描述
3.9.0 The $default argument was introduced.
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/class-wp-query.php:
    WP_Query::get()

Used By

  • wp-includes/link-template.php:
    wp_get_canonical_url()
  • wp-includes/category-template.php:
    wp_dropdown_categories()
  • wp-includes/general-template.php:
    paginate_links()
  • wp-includes/general-template.php:
    feed_links_extra()
  • wp-includes/general-template.php:
    get_search_query()
  • wp-includes/general-template.php:
    single_month_title()
  • wp-includes/general-template.php:
    wp_title()
  • wp-includes/general-template.php:
    post_type_archive_title()
  • wp-includes/class-wp.php:
    WP::handle_404()
  • wp-includes/query.php:
    wp_old_slug_redirect()
  • wp-includes/functions.php:
    do_feed()
  • wp-includes/link-template.php:
    get_next_comments_link()
  • wp-includes/link-template.php:
    get_previous_comments_link()
  • wp-includes/link-template.php:
    paginate_comments_links()
  • wp-includes/link-template.php:
    get_posts_nav_link()
  • wp-includes/user.php:
    wp_dropdown_users()
  • wp-includes/template.php:
    get_archive_template()
  • wp-includes/template.php:
    get_post_type_archive_template()
  • wp-includes/template.php:
    get_page_template()
  • wp-includes/post-template.php:
    get_body_class()
  • wp-includes/canonical.php:
    redirect_canonical()
  • wp-includes/canonical.php:
    redirect_guess_404_permalink()
  • wp-includes/comment-template.php:
    wp_list_comments()
  • wp-includes/comment-template.php:
    comments_template()
  • wp-includes/comment-template.php:
    get_comment_link()
  • wp-includes/comment.php:
    get_comment_pages_count()
  • wp-includes/comment.php:
    get_page_of_comment()
  • Show 22 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Getting Current Pagination Number

    
    <?php $paged = get_query_var( 'paged', 1 ); ?>
    
    <h1><?php printf( esc_html__( 'Currently browsing page %s', 'textdomain' ), $paged ); ?></h1>
    

    For getting the current pagination number on a static front page (Page template) you have to use the page query variable:

    
    <?php  $page = get_query_var( 'page', 1 );  ?>
    <h1><?php printf( esc_html__( 'Currently browsing page %s on a static front page', 'textdomain' ), $page ); ?></h1>
    

    Note: The query variable page holds the pagenumber for a single paginated Post or Page that includes the <!--nextpage--> Quicktag in the post content.

上一篇:get_query_template()

下一篇:WP_Query

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!