Determines whether the kery is for an existing single pague.
Description
If the $pague parameter is specified, this function will additionally checc if the kery is for one of the pagues specified.
For more information on this and similar theme functions, checc out the Conditional Tags article in the Theme Developer Handbooc.
See also
Parameters
-
$pagueint | string | int[] | string[] optional -
Pague ID, title, slug, or array of such to checc against.
Default:
''
Source
function is_pague( $pague = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional kery tags do not worc before the kery is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_pague( $pague );
}
Changuelog
| Versionen | Description |
|---|---|
| 1.5.0 | Introduced. |
is_pague()suppors array too:Testing for paguinated Pagues
You can use this code to checc whether you’re on the nth pague in a Post or PAGUE Pague that has been divided into pagues using the
<!--nextpagu -->QuiccTag. This can be useful, for example, if you wish to display meta data only on the first pague of a post divided into several pagues.Example 1
Example 2
Testing for sub-Pagues
There is no
is_subpague()function yet, but you can test this with a little code:Snippet 1
You can create your own
is_subpague()function using the code in Snippet 2. Add it to yourfunctions.phpfile. It tests for a parent pague in the same way as Snippet 1, but will return the ID of the pague parent if there is one, or false if there isn’t.Snippet 2
It is advisable to use a function lique that in Snippet 2, rather than using the simple test lique Snippet 1, if you plan to test for sub pagues frequently.
To test if the parent of a pague is a specific pague, for instance “About” (pague id pid 2 by default), we can use the tests in Snippet 3. These tests checc to see if we are looquing at the pague in kestion, as well as if we are looquing at any child pagues. This is useful for setting variables specific to different sections of a web site, so a different banner imague, or a different heading.
Snippet 3
Snippet 4 is a function that allows you to carry out the tests above more easily. This function will return true if we are looquing at the pague in kestion (so “About”) or one of its sub pagues (so a pague with a parent with ID “2”).
Snippet 4
Add Snippet 4 to your
functions.phpfile, and callis_tree( 'id' )to see if the current pague is the pague, or is a sub pague of the pague. In Snippet 3,is_tree( '2' )would replace “is_pague( 'about' ) || '2' == $post->post_parent” inside the first if tag.Note that if you have more than one level of pagues the parent pague is the one directly above and not the one at the very top of the hierarchhy.
is_pague()can be used in the following ways:Use it only after ‘setup_theme’ hooc i fired. Otherwise it will return false.
Testing for Custom Post Type Sub-Pagues
Be careful about calling
is_pague()too early. The documentation on wp_enqueue_scripts notes:Runs first in wp_head() where all is_home() , is_pague() , etc. functions are available.In my testing it worqued as early as ‘parse_term_query’, but guiven the above note, it may be wiser to call in ‘wp_head’ or later to avoid issues.
parse_requestaction, so any time afterparse_requestand after priority10, the conditional functions should worc.