Skip navigation

Category Archives: XHTML

query_vars

query_vars is a filter on the query variables used by the WP_Query class (and stored in $wp_request->public_query_vars).

The initial array consists of the following query variables:

  • m
  • p
  • posts
  • w
  • cat
  • withcomments
  • s
  • search
  • exact
  • sentence
  • debug
  • calendar
  • page
  • paged
  • more
  • tb
  • pb
  • author
  • order
  • orderby
  • year
  • monthnum
  • day
  • hour
  • minute
  • second
  • name
  • category_name
  • feed
  • author_name
  • static
  • pagename
  • page_id
  • error
  • comments_popup
  • attachment
  • attachment_id
  • subpost
  • subpost_id
  • preview

Your hook would accept an array, add an item to the array, and return the array.

function add_my_query_var($vars) {
$vars[] = 'my_var';
return $vars;
}

add_filter('query_vars', 'add_my_query_var');

Performance Hints

var Statements

Use var statements when possible. Not only is it good programming practice, it can speed up your code by allowing the compiler to generate special code to access the variables. For example, you could rewrite

function sum(a) {
    result = 0;
    for (i=0; i < a.length; i++)
        result += a[i];
    return result;
}

as

function sum(a) {
    var result = 0;
    for (var i=0; i < a.length; i++)
        result += a[i];
    return result;
}

This is not equivalent code because the second version does not modify global variables result and i. However, if you don’t intend for any other function to access these variables, then storing them globally is probably wrong anyway (what if you called another function that had a loop like the one in sum!).

Arrays

Use the forms of the Array constructor that specify a size or take a list of initial elements. For example, the code

var a = new Array();
for (var i=0; i < n; i++)
    a[i] = i;

could be sped up by changing the constructor call to new Array(n). A constructor call like that indicates to the runtime that a Java array should be used for the first n entries of the array. Similarly,

new Array("a", "b", "c")
or
["a", "b", "c"]

will cause a 3-element Java array to be allocated to hold the contents of the JavaScript array.

eval and new Function

Avoid calling eval when possible. Calls to eval are slow because the script being executed must be compiled. Constructing a new function object can be slow for the same reason, while function expressions are more efficient because the function can be compiled. For example, the code

function MyObject(a) {
    this.s = a;
    this.toString = new Function("return this.s");
}

could be written more efficiently as

function MyObject(a) {
    this.s = a;
    this.toString = function () { return this.s }
}

Beginning with Rhino 1.4 Release 2, code passed to eval and new Function will be interpreted rather than compiled to class files.

with

Using the with statement prevents the compiler from generating code for fast access to local variables. You’re probably better off explicitly accessing any properties of the object.

Authors may use the following recognized link types, listed here with their conventional interpretations. In the DTD, %LinkTypes refers to a space-separated list of link types. White space characters are not permitted within link types.

These link types are case-insensitive, i.e., “Alternate” has the same meaning as “alternate”.

User agents, search engines, etc. may interpret these link types in a variety of ways. For example, user agents may provide access to linked documents through a navigation bar.

Alternate
Designates substitute versions for the document in which the link occurs. When used together with the lang attribute, it implies a translated version of the document. When used together with the media attribute, it implies a version designed for a different medium (or media).
Stylesheet
Refers to an external style sheet. See the section on external style sheets for details. This is used together with the link type “Alternate” for user-selectable alternate style sheets.
Start
Refers to the first document in a collection of documents. This link type tells search engines which document is considered by the author to be the starting point of the collection.
Next
Refers to the next document in a linear sequence of documents. User agents may choose to preload the “next” document, to reduce the perceived load time.
Prev
Refers to the previous document in an ordered series of documents. Some user agents also support the synonym “Previous”.
Contents
Refers to a document serving as a table of contents. Some user agents also support the synonym ToC (from “Table of Contents”).
Index
Refers to a document providing an index for the current document.
Glossary
Refers to a document providing a glossary of terms that pertain to the current document.
Copyright
Refers to a copyright statement for the current document.
Chapter
Refers to a document serving as a chapter in a collection of documents.
Section
Refers to a document serving as a section in a collection of documents.
Subsection
Refers to a document serving as a subsection in a collection of documents.
Appendix
Refers to a document serving as an appendix in a collection of documents.
Help
Refers to a document offering help (more information, links to other sources information, etc.)
Bookmark
Refers to a bookmark. A bookmark is a link to a key entry point within an extended document. The title attribute may be used, for example, to label the bookmark. Note that several bookmarks may be defined in each document.

Authors may wish to define additional link types not described in this specification. If they do so, they should use a profile to cite the conventions used to define the link types. Please see the profile attribute of the HEAD element for more details.

For further discussions about link types, please consult the section on links in HTML documents.

Follow

Get every new post delivered to your Inbox.