返回介绍

get_query_var()

发布于 2017-09-11 00:03:24 字数 4372 浏览 916 评论 0 收藏 0

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

Retrieve variable in the WP_Query class.


description


参数

$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 );
}

更新日志

Versiondescription
3.9.0The $default argument was introduced.
1.5.0Introduced.

相关函数

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文