wp-api | Parameter (Computer Programming) | Php

October 15, 2016 | Author: Anonymous | Category: PHP
Share Embed


Short Description

A WordPress template tag is made up of three components: A PHP code tag A WordPress function Optional parameters These a...

Description

Template Tags/Anatomy of a Template Tag Contents 1 Introduction 2 PHP code tag 3 WordPress function 4 Optional parameters 5 Further reading

Introduction This document provides a brief examination of the animal known as the WordPress template tag, to help those who may be new to WordPress and PHP understand what template tags are and how they're used. A WordPress template tag is made up of three components: A PHP code tag A WordPress function Optional parameters These are explained below.

PHP code tag WordPress is built with the PHP scripting language. Though you certainly don't need to be a PHP developer to use it, knowing a little about the language can go a long way in getting the most out of WordPress. Here we provide a tiny bit of that PHP knowledge: The above shows the opening () tag elements used to embed PHP functions and code in a HTML document, i.e. web page. There are a number of ways to embed PHP within a page, but this is the most "portable," in that it works on nearly every web server—as long as the server supports PHP (typically a document's filename also needs to end with the extension .php, so the server recognizes it as a PHP document). Anything within this tag is parsed and handled by the PHP interpreter, which runs on the web server (the interpreter is the PHP engine that figures out what the various functions and code do, and returns their output). For our purposes, the PHP tag lets you place WordPress functions in your page template, and through these generate the dynamic portions of your blog.

WordPress function A WordPress or template function is a PHP function that performs an action or displays information specific to your blog. And like a PHP function, a WordPress function is defined by a line of text (of one or more words, no spaces), open and close brackets (parentheses), and typically a semi-colon, used to end a code statement in PHP. An example of a WordPress function is: the_ID(); the_ID() displays the ID number for a blog entry or post. To use it in a page template, you slip it into the PHP tag shown above: This is now officially a WordPress template tag, as it uses the PHP tag with a WordPress function.

Optional parameters The final item making up a template tag is one you won't necessarily make use of unless you want to customize the tag's functionality. This, or rather these, are the parameters or arguments for a function. Here is the template function bloginfo(), with the show parameter being passed the 'name' value: If your blog's name is Super Weblog, the bloginfo() template tag, when using 'name' as the show parameter value, will display that name where it's embedded in your page template. Not all template tags accept parameters (the_ID() is one), and those which do accept different ones based on their intended use, so that the_content() accepts parameters separate from those which get_calendar() can be passed.

Further reading See the following Codex pages for more information on WordPress templates and template tags: Templates

How to Pass Tag Parameters Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/Anatomy_of_a_Template_Tag" Categories: Template Tags | Design and Layout | Advanced Topics

Template Tags/How to Pass Tag Parameters Contents 1 Introduction 2 Tags without parameters 3 Tags with PHP function-style parameters 4 Tags with query-string-style parameters 5 Types of parameters 5.1 String 5.2 Integer 5.3 Boolean

Introduction Template tags are PHP functions you can embed in your WordPress page templates to provide dynamic blog content. And like PHP functions, many template tags accept arguments, or parameters. Template tag parameters are variables you can use to change a tag's output or otherwise modify its action in some way. Think of parameters as user options or settings that allow you to customize how a template tag works. In regards to parameters, WordPress template tags come in three "flavors." These are described below: 1. Tags without parameters 2. Tags with PHP function-style parameters 3. Tags with query-string-style parameters

Tags without parameters Some template tags do not have any options, and thus have no parameters you can pass to them. The template tag the_author_firstname() is one that accepts no parameters. This tag simply displays the first name of the author for a post. Tags without parameters should have nothing between the tag function's opening and closing brackets (parentheses):

Tags with PHP function-style parameters For template tags that can accept parameters, some require them to be in the default PHP style. For these, parameters are passed to a tag function by placing one or more values inside the function's parentheses, or brackets. The bloginfo() tag accepts one parameter (known as the show parameter) that tells it what information about your blog to display: The wp_title() tag accepts two parameters: the first is the sep or separator parameter, and the second the echo or display parameter: The first is enclosed in single-quotes and the second is not because the first is a string, and the second a boolean parameter. (See Types of parameters for information on parameter types and how to use them.) Important points to keep in mind for PHP function-style parameters: Some functions take multiple parameters. Multiple parameters are separated by commas. The order of parameters is important! When passing parameters to a template tag's function, make sure you specify values for all parameters up to the last one you wish to modify, or the tag may not work as expected. For example, the template tag get_archives() has six parameters: To display the archives list the way you want, let's say you only need to modify the third (format) and fifth (after) parameters. To do this, you also need to make sure to enter default values for the first, second and fourth parameters, as well:

Notice the use of single-quotes to denote empty parameter values, which in this case forces defaults for those specific parameters. Be aware that defaults can be overwritten when passing empty parameters, as is the case of a parameter specifying a string of text, and there's no way to pass an empty boolean value. So check the documentation for a parameter's default, and when one is specified use it as your parameter value (also see Types of parameters for information on parameter types). The sixth parameter was left off; this is because WordPress uses the default for any remaining parameters left unspecified. Make sure to follow the documentation for a template tag carefully, and place your parameters in the order the template function expects. Finally, to use the defaults for all parameters in a template tag, use the tag with no parameter values specified:



Tags with query-string-style parameters The last type of template tag makes use of what's called a query-string style to pass parameters to the tag. These provide a convenient 'wrapper' to tags which use the PHP function parameter style and have a relatively large number of parameters. For example, the template tag wp_list_cats() is a wrapper to list_cats(), a tag with eighteen parameters! If you want to set the exclude parameter in list_cats() (seventeenth in the parameter list) and leave the rest at their defaults, you have to do this: Or you can use wp_list_cats(): So query-string style tags are useful in that they let you change the values of just those parameters you require, without needing to provide values for all or nearly all of them. However, not all PHP function-style template tags have a query-string style equivalent. (Also note that names for tags that accept query-string style parameters usually start with a 'wp_' prefix, such as wp_list_cats(), but check the documentation on a tag to verify its method for accepting parameters, if any.) The tag wp_list_authors() has six parameters, of which we set three here: First, all the parameters together are enclosed by either single or double quotes. Then each parameter is entered in the parameter=value format, while these are separated with an ampersand (&). Broken down, the tag as shown above states: Parameter show_fullname (a boolean type parameter) equals 1 (true). AND Parameter feed (a string type parameter) equals rss. AND Parameter optioncount (a boolean type parameter) equals 1 (true). (See Types of parameters for information on parameter types and how to use them.) Parameters in the query-string style do not have to be entered in a specific order. The only real concern is assuring parameter names are spelled correctly. If legibility is a problem, you can separate parameters with a space: You can also spread a query-string over several lines (note the specific format of enclosing each parameter/value pair in single quotes and a dot starting each new line): There are a few limitations when using query-string style tags, among which you cannot pass certain characters, such as the ampersand or a quote mark (single or double). In those cases, you can use an associative array:

Show Character Set Displays the character set your blog is using (ex: utf-8) Character set:

Show Blog Description Displays Tagline for your blog as set in the Administration panel under General Options.

Parameters See get_bloginfo()

Related bloginfo, bloginfo_rss, get_bloginfo, get_bloginfo_rss, wp_title, wp_get_archives, get_calendar, get_posts, wp_list_pages, wp_page_menu, wp_dropdown_pages, wp_loginout, wp_register, wp_logout_url, query_posts, rss_enclosure

How to pass parameters to tags Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/bloginfo" Category: Template Tags

Template Tags/bloginfo rss Contents 1 Description 2 Usage 3 Example 3.1 Show Blog Title and Link 4 Parameters 5 Related

Description Displays information about your blog, mostly gathered from the information you supply in Users > Your Profile and General Options from the WordPress Administration Panels. This function is identical to bloginfo() except it strips any markup from the output for use in WordPress' syndication feeds.

Usage

Example Show Blog Title and Link Displays blog name and url in title and link tags of RSS feed.



Parameters show (string) Informational detail about your blog. Valid values: 'name' - Weblog title; set in General Options. (Default) 'description' - Tagline for your blog; set in General Options. 'url' - URL for your blog's web site address. 'rdf_url' - URL for RDF/RSS 1.0 feed. 'rss_url' - URL for RSS 0.92 feed. 'rss2_url' - URL for RSS 2.0 feed. 'atom_url' - URL for Atom feed. 'comments_rss2_url' - URL for comments RSS 2.0 feed. 'pingback_url' - URL for Pingback (XML-RPC file). 'admin_email' - Administrator's email address; set in General Options. 'charset' - Character encoding for your blog; set in Reading Options. 'version' - Version of WordPress your blog uses. The following work in WordPress version 1.5 or after: 'html_type' - "Content-type" for your blog. 'wpurl' - URL for WordPress installation. 'template_url' - URL for template in use. 'template_directory' - URL for template's directory. 'stylesheet_url' - URL for primary CSS file. 'stylesheet_directory' - URL for stylesheet directory.

Related bloginfo, bloginfo_rss, get_bloginfo, get_bloginfo_rss, wp_title, wp_get_archives, get_calendar, get_posts, wp_list_pages, wp_page_menu, wp_dropdown_pages, wp_loginout, wp_register, wp_logout_url, query_posts, rss_enclosure

How to pass parameters to tags Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/bloginfo_rss" Categories: Template Tags | Feeds

Template Tags/cancel comment reply link Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays a link which cancels the replying to a previous comment (a nested comment) and resets the comment form back to the default state.

Usage

Example

Parameters text (string) Text to display as a link. Default is 'Click here to cancel reply.'

Related Template_Tags/comment_reply_link

Migrating_Plugins_and_Themes_to_2.7/Enhanced_Comment_Display Retrieved from "http://codex.wordpress.org/Template_Tags/cancel_comment_reply_link"

Template Tags/category description Contents 1 Description 2 Usage 3 Examples 3.1 Default Usage 3.2 Using Category Slug 3.3 With Category Title 4 Parameters 5 Related

Description Returns the description of a category.

Usage

Examples Default Usage Displays the description of a category, given it's id, by echoing the return value of the tag. If no category given and used on a category page, it returns the description of the current category. Result: WordPress is a favorite blogging tool of mine and I share tips and tricks for using WordPress here. Note: if there is no category description, the function returns a br tag

Using Category Slug Displays the description of a category, using a category slug.

With Category Title : Result: Currently browsing WordPress: WordPress is a favorite blogging tool of mine and I share tips and tricks for using WordPress here.

Parameters category (integer) The numeric ID of the category for which the tag is to return the description. Defaults to the current category, if one is not set.

Related the_category, the_category_rss, single_cat_title, category_description, wp_dropdown_categories, wp_list_categories, in_category, get_category_parents, get_the_category get_category_link,

How to pass parameters to tags Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/category_description" Category: Template Tags

Template Tags/category nicename This page is marked as incomplete. You can help Codex by expanding it.

Description Displays the category slug (or category nicename) a post belongs to. Must be used within The Loop. Outputs sanitized version of category name: single_cat_title.

Usage

Related the_category, the_category_rss, single_cat_title, category_description, wp_dropdown_categories, wp_list_categories, in_category, get_category_parents, get_the_category get_category_link,

How to pass parameters to tags with PHP function-style parameters Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/category_nicename" Categories: Stubs | Template Tags

Template Tags/comment ID Contents 1 Description 2 Usage 3 Examples 3.1 Default Usage 3.2 Comment ID as Anchor ID 4 Parameters 5 Related

Description Displays the numeric ID of a comment. This tag must be within The Loop, or a comment loop.

Usage

Examples Default Usage This is comment for all comments.

Comment ID as Anchor ID Uses the comment ID as an anchor id for a comment.

Example > Email Comment Author <

Parameters linktext (string) Link text for the email link. Default is the comment author's email address. before (string) Text to display before the link. There is no default. after (string) Text to display after the link. There is no default.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link

How to pass parameters to tags with PHP function-style parameters Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_author_email_link" Category: Template Tags

Template Tags/comment author link Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the comment author's name linked to his/her URL, if one was provided. This tag must be within The Loop, or a comment loop.

Usage

Example Comment by:

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_author_link" Category: Template Tags

Template Tags/comment author rss Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the comment author's name formatted for RSS. Typically used in the RSS comment feed template. This tag must be within The Loop, or a comment loop.

Usage

Example comment by:

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_author_rss" Categories: Template Tags | Feeds

Template Tags/comment author url Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the comment author's URL (usually their web site), not linked. This tag must be within The Loop, or a comment loop.

If the author provided no URL, this will display the URL of the current page instead. The tag get_comment_author_url returns an empty string in this case.

Usage

Example Displays comment author's URL as a link, using comment author's name as part of the link text.

Examples Default Usage web site:

Link Text and Styling Displays comment author's URL as text string Visit Site of Comment Author and adds bullets before and after the link to style it. • Visit Site of Comment Author •

Parameters linktext (string) Link text for the link. Default is the comment author's URL. before (string) Text to display before the link. There is no default.

after (string) Text to display after the link. There is no default.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link

How to pass parameters to tags with PHP function-style parameters Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_author_url_link" Category: Template Tags

Template Tags/comment date Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the date a comment was posted. This tag must be within The Loop, or a comment loop.

Usage

Example Displays the comment date in the format "6-30-2004": Comment posted on

Parameters d (string) Formatting for the date. Defaults to the date format set in WordPress. See Formatting Date and Time.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link

How to pass parameters to tags Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_date" Category: Template Tags

Template Tags/comment excerpt Contents 1 Description 2 Usage 3 Example

4 Parameters 5 Related

Description Displays an excerpt (maximum of 20 words) of a comment's text. This tag must be within The Loop, or a comment loop. This tag will work within a comment loop.

Usage

Example Latest comment:

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_excerpt" Category: Template Tags

Template Tags/comment form title Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays text based on comment reply status. This only affects users with Javascript disabled or pages without the comment-reply.js JavaScript loaded. This tag is normally used directly below and before the comment form.

Usage

Example

Parameters noreplytext (string) Optional. Text to display when not replying to a comment. Default is 'Leave a Reply' replytext (string) Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to. Default is 'Leave a Reply to %s' linktoparent (boolean) Optional. Boolean to control making the author's name a link to their comment. Default is TRUE.

Related Migrating_Plugins_and_Themes_to_2.7/Enhanced_Comment_Display

Retrieved from "http://codex.wordpress.org/Template_Tags/comment_form_title"

Template Tags/comment link rss Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the URL to an entry's comments formatted for RSS. Typically used in the RSS comment feed template. This tag must be within The Loop, or a comment loop.

Usage

Example

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_link_rss" Categories: Template Tags | Feeds

Template Tags/comment reply link Description Displays a link that lets users post a comment in reply to a specific comment. If JavaScript is enabled and the comment-reply.js JavaScript is loaded the link moves the comment form to just below the comment.

Usage

Related cancel_comment_reply_link Migrating_Plugins_and_Themes_to_2.7/Enhanced_Comment_Display Retrieved from "http://codex.wordpress.org/Template_Tags/comment_reply_link"

Template Tags/comment text Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description

Displays the text of a comment. This tag must be within The Loop, or a comment loop.

Usage

Example Displays the comment text with the comment author in a list () tag. Comment by :

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_text" Category: Template Tags

Template Tags/comment text rss Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the text of a comment formatted for RSS. Typically used in the RSS comment feed template. This tag must be within The Loop, or a comment loop.

Usage

Example

Parameters This tag has no parameters.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_text_rss" Categories: Template Tags | Feeds

Template Tags/comment time

Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the time a comment was posted. This tag must be within The Loop, or a comment loop.

Usage

Example Dsiplays the comment time in the format "22:04:11". comment timestamp:

Parameters d (string) Formatting for the time. Defaults to the time format set in WordPress. See Formatting Date and Time.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link

How to pass parameters to tags Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_time" Category: Template Tags

Template Tags/comment type Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the type of comment (regular comment, Trackback or Pingback) a comment entry is. This tag must be within The Loop, or a comment loop.

Usage

Example to :

Parameters comment (string) Text to describe a comment type comment. Defaults to 'Comment'. trackback

(string) Text to describe a Trackback type comment. Defaults to 'Trackback'. pingback (string) Text to describe a Pingback type comment. Defaults to 'Pingback'.

Related comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comments_rss_link, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, previous_comments_link, next_comments_link

How to pass parameters to tags with PHP function-style parameters Go to Template Tag index Retrieved from "http://codex.wordpress.org/Template_Tags/comment_type" Category: Template Tags

Template Tags/comments link Contents 1 Description 2 Usage 3 Example 4 Parameters 5 Related

Description Displays the URL to a post's comments. This tag must be within The Loop, or the loop set up for comments.

Usage

Example
View more...

Comments

Copyright © 2017 DATENPDF Inc.