Wordpress Flashcards

1
Q

What PHP function can be called to get the name of the blog (for templating)?

A

bloginfo(‘name’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What PHP function can be called to get the name of the stylesheet?

A

bloginfo(‘stylesheet_url’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What function is used to include the header of a theme file?

A

get_header()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What function is used to include the footer of a theme file?

A

get_footer()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What function is called just before the end of the head block of a theme to allow wordpress to ‘hook’ into the head?

A

wp_head()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What function is called just before the end of the body tag, so that wordpress can provide hooks for plugins?

A

wp_footer()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function is used to get the template directory?

i.e. in templates, you may need to specify the root folder the images and content lives in

A

echo get_template_directory_uri();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you setup a query for posts?

A

query_posts(‘posts_per_page’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you iterate through the posts from a query?

A

while(have_posts()) {
the_post();
the_permalink();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you get the heading of a post?

A

the_post();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you get the link to a post?

A

the_permalink();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Once you’ve made your query using query_posts - what should you do to clean up?

A

wp_reset_query()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Should a theme use query_posts?

A

No - it may fail, and is inefficient. I would use pre_get_posts action.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What function do you call to get the content of a post?

A

the_content();

This is normally done in a page called single.php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do we get the thumbnail for the post?

A

the_post_thumbnail(array(300, 300));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can we determine if a page is the front page?

A

You can use the function

is_front_page();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What method gives you the title?

A

the_title();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What method gives you the permalink?

A

the_permalink()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Why is it we can see a 980px layout on a 320px size iPhone screen?

A

There is the notion of viewports and screen sizes. The viewport is 980px, and the screen size is 320px. The web page is first loaded into the viewport then resized to the screen size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the following meta-tag doing?

meta name=”viewport” content=”width=device-width”

A

It is telling the device to match the viewport width with the device width. Using the meta tag is probably the best supported method, and easier than specifying viewport sizes on a per device basis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

The initial-scale part of the meta tag does what?

A

It controls the amount of zoom applied to the webpage - note, it is just the initial zoom, the user can change it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Because some older browsers do not know how to deal with media queries, what library can we use to fix this?

A

respond.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Whats the difference between
@media and (max-width:632px)
and
@media screen and (max-width:632px)

A

Not a lot - it’s very similar - however, the use of the term screen specifies we are only targetting screen media types, and not other types such ‘print’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Whats the difference between
@media screen and (max-width:632px)
@media only screen and (max-width:632px)

A

Basically the ‘only’ keyword hides the media query from older browsers. According to the W3C, the user-agent must process the only keyword as if it isn’t present, but older browsers don’t recognise it, so they ignore it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is code like Respond.js and Htmlshiv referred to as?
Pollyfil. - or Pollyfiller - because they fill the gaps in terms of code that is not present on older browsers.
26
What is a breakpoint in regards to CSS?
The moment where the browser layout switches between media queries, from one layout to another.
27
How do we space our min-width / max-width values so there isn't overlap?
Make sure the styles min-width value is 1px higher than the max-width
28
How do you setup XAMPP security?
/Applications/XAMPP/xamppfiles/xampp security
29
In XAMPP - if you get writing file permissions, what do you need to do?
Make sure you have the Wordpress installation saved with the right user for Webserver. Under XAMPP it is likely daemon.
30
What should you install in order to obtain better developer tools?
Developer plugin by Automatic. This will include additional plugins.
31
What base theme can be used to start a new web theme?
_s or Underscores | written by automatic
32
When a user comes to a WP site, they will enter a URL for the resource they want - for instance "http://foobar.com/about". That page gets mapped to what?
Different pages have different page types. You can think of these as templates. So the about page may have a type of "Page". So it will be presented based on how the resource is mapped to the templates.
33
In styles.css you can add tags that describe the theme - what is the restriction on this?
You must use the tags that are made available by Wordpress.
34
Header.php page contains all the elements that are needed at the top of each HTML page, including:
The doctype, opening HTML, meta and title tags. Blog info, style sheets and website navigation.
35
The content files (page etc) are..
scaffolding files that call the header, footer and other files based on the content type.
36
The footer.php file contains...
information that typically goes at the bottom of the page - including closing tags - and in some cases, the calls to footer sidebars / widgets.
37
The index.php scaffolding file is important - why?
It's purpose is to show the blogs index page, or any other index page - it is used if the system can't locate the designated template page, such as page.php or single.php.
38
What does get_template_part do?
Loads a template part - you can call it like such to get the content part. get_template_part('content'); If you call it like this: get_template_part('content', 'none'); it will load the file "content-none.php".
39
In order to prevent naming conflicts with the Wordpress core - what do we need to do?
Make sure all functions are uniquely named (Wordpress suggests either prefixing them with the theme name - or enclosing them in a class).
40
What does page.php do?
Scaffolding page for content, contains the "the_content" call that calls content-page.php
41
What does the search.php file do?
Scaffolding file where search results are shown.
42
What does the archive.php file do?
Scaffolding file in which archived pages are shown.
43
What does the comments.php file do?
Scaffolding file that is used to display comments.
44
What does the 404 file do/
Scaffolding file that is used to display 404 errors when files cannot be found.
45
What is the rtl.css file for?
It is a CSS file that is used for right-to-left languages.
46
What is the README.md file for?
Github readme file.
47
What is the functions.php file?
Add custom functions to the theme.
48
What is a Post Format?
It is a piece of metadata that can be used to customise the presentation of a post. This feature provides a standardised list of formats that are available to all themes that support the feature. The post format types are defined by Wordpress and new ones cannot be added. The author can select the post format from a radio button when creating a new post.
49
If we want to add custom JavaScript or Styles to a page - how do we do this?
We must use the functions.php file, and in the topcat_scripts function - call: wp_enqueue_scripts wp_enqueue_scripts functions.
50
What is the difference between content-sidebar.css and sidebar-content.css?
content-sidebar is for sidebars on the right of the content. sidebar-content is for sidebars on the left of the content.
51
What file extension does localisation files have?
.pot, located in the themes/yourthemename/languages folder
52
What does the following JS file do in the theme JS directory directory? skip-link-focus-fix.js
In opera and webkit browsers, when using the keyboard instead of the mouse to click on a skiplink, the browsers don't properly move focus to their target. This is a fix for this.
53
What is a skip link?
A navigation link that is usually used to link to parts of the same page, to allow users to skip over repetitive content.
54
What goes in the "inc" folder of the theme?
Files that are used for extending the functionality of the theme. Generally PHP files.
55
Does wordpress require tabs or spaces for the PHP coding standards?
tabs
56
Wordpress class names should use what convention?
Capitalised words, with underscores to separate them.
57
Which is correct for the Wordpress CSS coding standard? ``` h1, h2, h3 { } or h1, h2, h3 { } ```
The second one: ``` h1, h2, h3 { // Do CSS stuff here } ```
58
What third party tool can be used to fix coding stanards issues with wordpress themes / plugins?
PHP Codesniffer
59
How do child themes allow functions to be "pluggable"?
Because a child theme can also include a "functions.php" file - it's possible to override the function name in the parent theme. Simply redeclare it here - and it will override the parent themes function.
60
What must you do to ensure child themes work correctly?
Child themes are loaded before parent themes - so you must use the if (!function_exists('function_name')) construct to ensure your theme will play nicely with child themes.
61
If we are planning to submit the theme to wordpress.org, what do we have to remember with regards to fonts?
We must include the fonts locally - and not use google.com font repository.
62
Often it's enough to use wp_enqueue_style('nameoffont', 'location of font'); to get a font to work. But if there is an issue (such as wanting to use a font used by the WP core, that for some reason cant be accessed by the theme) - what should you do?
Register the font first: wp_register_style('topcat-headings-font', get_template_directory_uri() . '/css/open-sans.css'); wp_enqueue_style('topcat-headings-font');
63
In style.css the "reset" section overrides a number of settings - why?
The purpose of the reset section is override some of the default style sheet settings for reach browser. This means all browsers start with the same settings as opposed to their own settings.
64
Is the "reset" section in style.css meant to be changed?
no - in general it should be left as is.
65
How do you configure the tagline?
Settings | General | Tagline
66
What does the body_class function do?
It inserts the given classes into the body tag of the html based on where you are in the WP hiearchy.
67
What is the difference between the functions "the_title()" and "get_the_title"?
the_title will echo the title of the page out directly into HTML. get_the_title returns the title string.
68
Why does wordpress sometimes use query strings to pass data to functions?
Because some functions take a lot of parameters (some up to 24), and it allows you to just set the parameters you want to set.
69
What is the Yoda condition?
Putting the comparison variable on the right of an equality test to ensure you don't accidentally use an assignment operator. if (true === $theForce)
70
What are the naming conventions for Wordpress?
Functions and variables should be lowercase Classnames should always be capitalised words All constants should be uppercase CamelCase should never be used File names should be lowercase with words separated by hyphens.
71
What must be done with regards to HTML?
HTML code must pass validation of the W3C validator. All tags must be closed.
72
What does the constant WP_DEBUG_LOG do?
If set to true, stores all errors warnings and notifications in a debug.log file in wp-content folder.
73
What does WP_DEBUG_DISPLAY do?
Set to true by default, this option inserts all debug information as and when it happens. If you set it to false, you should really set WP_DEBUG_LOG to true so that the data goes somewhere.
74
What does the constant SCRIPT_DEBUG do?
Makes the wordpress environment use the development styles and scripts in case you are developing anything in the admin area.
75
What does the constant SAVEQUERIES do?
When set to true, saves all queries to the database as well. Causes heavy performance issues - but useful for debugging.
76
Wordpress theme names should never include any...
numbers - or else it wont be shown in the theme browser.
77
What is the absolute bare minimum number of files that can be in a theme?
index. php | style. css
78
What needs to be at the top of the style.css file?
Meta data in the form of comments: ``` Theme Name: foobar Theme URI: myurl Author: My name Author URI: My url Description: Version: License: License URI: Tags: Note - these tags are defined by WP Text Domain: Unique Identifier used for localisation - usually lowercase with no spaces version of themename ```
79
How do you add a screenshot to your theme?
Use an image of 600x450px, and call it screenshot.png. Place it in the root of the theme folder.
80
What are the basic template files that can be used to build a theme?
header. php footer. php sidebar. php comments. php searchform. php
81
What does the wp_title function do?
Returns the title of the page, based on where you are viewing the page from. Can be used anywhere in a theme, but most commonly in the title tag.
82
Which function holds the data required to display the admin bar when a user is logged in?
wp_footer()
83
If there is a 30px space at the top of your site, what have you likely forgot?
wp_footer() function
84
Is a comments.php template required in your theme?
Yes - if you want to show comments (you probably do). It used to have a default version that would be used if it wasn't present, however this has been deprecated.
85
Is a searchform.php template required in your theme?
No - wordpress provides a default one if there isn't one in your theme.
86
Rather than using php's 'include' keyword, wordpress provides a set of functions that can be used to include the appropriate templates - what are they?
``` get_header() get_footer() get_sidebar() get_search_form() comments_template() ```
87
get_header, get_footer and get_sidebar can all be passed a string, what does that do?
You can specify an alternative template other than the default to use.
88
How would you specify a different sidebar to be used on specific pages?
Create a file called sidebar-secondary.php, then call it in the template you want to use it in like this: get_sidebar('secondary');
89
comments_template(), like get_header, can take a parameter specifying a special template - but what is different about it from get_header?
It requires a full filename and a relative path. '/custom-comments.php'. It also takes a second parameter that determines whether to have the comment separated by type.
90
What is the purpose of the functions.php in wordpress?
To setup WP functionality such as post-thumbnails, or custom post types To define functions that can be used throughout the theme To change the WP admin or add in options page
91
What does add_theme_support function do?
Adds support for certain features available within Wordpress to the theme.
92
What is the list of features that can be added via add_theme_support function?
``` post-formats post-thumbnails custom-background custom-header automatic-feed-links html5 title-tag ```
93
What does the theme support "posts-formats" provide?
Post formats are a piece of meta-data that can be used to customise the way a post appears. Themes that implement posts-formats are not required to support all of the post types.
94
Can new post-formats be added to wordpress?
No, not through themes or even plugins.
95
What does the theme support for posts-thumbnails provide?
The post-thumbnail (now called featured image) is an image that is chosen as the representative image for a post, page or custom post type. This adds a link on the edit post / edit page screens that allows you to set an image.
96
What does the theme support for html5 provide/
Allows the use of HTML5 markup in search forms, comment forms, galleries and captions.
97
What does the theme support for title tag do?
It allows you to control the title tag of a page. You should provide backwards compatability for older versions, since it's a relatively recent addition.
98
How would you create a template for an about page?
You use the page.php template - and then add the name for the page (based on the pages slug) page-{name}.php so it would be: page-about.php
99
What is single.php template for?
Single pages i.e. individual posts. It is also used when a custom post type needs to be displayed. If you are using custom post types, then you can target the post types. single-post.php -> template for plain posts (all individual posts fall back to single.php if single-post.php does not exist). So you can use single-{post-type}.php for all custom post types, and rely on single.php for standard posts.
100
What page is used if you link to post attachments?
single. php, however you can specify mime-type pages as well. You can also specify a "attachment.php" page for a simpler layout. attachment. php image. php video. php text. php
101
When is the archive.php file used?
It is used whenever a group of posts or information is being accessed through a query.
102
What pages can override the archive.php file?
There are a lot of them - but at the next level down: taxonomy. php category. php tag. php author. php date. php These can each be broken down further. i.e. category-{catname}.php
103
When is the front-page template used in WP?
When a static front page has been selected from the wordpress admin options, or it will be the default landing page if it exists, when a user goes to the base URL.
104
When is the home.php template used?
In two circumstances. As the main template for the website, or the main listing page template of your site when you have setup a static front page using the reading settings.
105
What is the search.php page used for?
Displays the results of any search performed on the site.
106
What url do you have to call to perform a search?
Perform a GET request on the home page with a query string: foobar.com?s=shoes Does a search for shoes - and will call search.php to present the results.
107
What function fetches the search results?
the_search_query();
108
The 404.php template is displayed by PHP when...
it can't find the result for a query, a specific page, or post.
109
How do you create a custom page template?
You have to create a new file in the theme directory. It must not conflict naming wise with any of the reserved template names in the WP template hiearchy. It requires a meta data header like the CSS files: * Template Name: Custom page type 1
110
What is a post format?
It's a way of adding meta data to a post allowing more specific formatting and styling in a theme.
111
By default post types can be used for posts and custom post types, to add post formats to pages, you need to...
``` call add_post_type_support // Add post-formats to post_type 'page' add_post_type_support('page', 'post-formats'); ```
112
How can I test whether a post has a specific post format?
if (has_post_format('video')) : endif;
113
How would you get the post format as a string?
$format = get_post_format($post_id);
114
What is the most common way to get the post format?
Call in a special template part: get_template_part('content', get_post_format()); This code is using the result of get_post_format as a parameter to specify which template get_template_part should use.
115
How does get_template_part work?
It assumes the name of the template part to include is made of the components - slug and the second parameter. so: get_template_part('content', 'video'); will look for content-video.php. If it can't find content-video.php, it will look for content.php. If it can't do that - it will just fail silently and not load anything. You can add a path to a directory as part of the slug if you are keeping these files in different directories.
116
What is a good directory structure for a theme?
/ - the root directory with main template files and style.css lives. /images/ main folder for all the images used in the theme. /js/ All javascript files /languages/ multilingual files stored here /css/ Any additional css files (on top of style.css) /inc/ additional php files for theme /scss or /less - precompiler css files - compile down into style.css in root
117
wp_register_style wp_register_script These functions are used for...
Tells WP that a style or script is available for use, and gives them a handle.
118
wp_enqueue_style wp_enqueue_script These functions are used for...
Used to add the style sheet to a generated WP page through either wp_head, or wp_footer
119
What does add_action function do?
It's a wordpress hook - and it lets you call a specified function at a specified time. add_action('after_setup_theme', 'prowordpress_setup'); prowordpress_setup is a custom function that is called when the "after_setup_theme" action occurs.
120
What function do you use to include a style sheet/
wp_enqueue_style
121
Which action hook should you use to load scripts and styles that are meant to be viewed on the front end?
wp_enqueue_scripts
122
Does WP_Query make database calls?
Not itself no, it acts as a gateway.
123
What are the two main things that happens in the main index.php file for Wordpress?
Themes are enabled define('WP_USE_THEMES', true); and the wordpress environment is loaded: require( dirname( __FILE__ ) . '/wp-blog-header.php' );
124
Which file is responsible for setting up wordpress, making the database connections etc?
wp-load.php
125
How are have_posts and the_post related to WP_Query/
They are functional wrappers around that class.
126
What happens when have_posts reaches the end (i.e. it has looped through the counter it contains, and reached the end and returned false instead of true)?
It calls rewind_posts() so that Wordpress is ready to setup another loop should it need to.
127
What does the_post do?
When you call the_post, it goes through the current posts array, and sets up the data that is used to get the template tags, so you can start crafting the templates. It also sets up the global $post variable and advances the loop counter, ready to access the next post when the_post () is called again.
128
Do you need to loop everytime when setting up posts?
You should - as this is convention in Wordpress - even if you THINK you only have one post for a specific page, there is no guarentee that if you sell the theme, that rule will be broken.
129
What are the three functions that WP gives you to customise a query?
query_posts get_posts WP_Query
130
How might you call query_posts to include posts from category number '5', and order the results in ascending format, with 2 posts per page.
``` query_posts( 'cat' => 5, 'posts_per_page' => 2, 'order' => 'ASC' ); ```
131
How would you loop through the results of a call to query_posts?
query_posts("cat=5"); if (have_posts()): while(have_posts()):the_post(); // Do stuff endwhile; endif;
132
Other than calling query_posts, how else can you retrieve the posts?
Use get_posts(); ``` $new_posts = get_posts($args); foreach($newposts as $post): setup_postdata($post); // Do stuff using normal template tags endforeach; ``` wp_reset_postdata();
133
Do you need to use setup_postdata() in a loop when using get_posts to get the posts?
``` No, if you don't, you don't setup the post tags, but it's not required, and you can immediately get data from the indvidual $post variables from the $posts array. $posts = get_posts($args); foreach($posts as $post): echo $post->post_title; echo $post->post_content; endforeach; ```
134
If you have used get_posts to retrieve an array of posts, there are two ways you can deal with output the data - you can either display the raw data, or let wordpress format the data. Assuming the individual post is stored in a variable called $post - how would you print the post_contet for each method?
``` // Raw echo $post->post_content; ``` ``` // Formatted echo apply_filters('the_content', $post->post_content); ```
135
What is one difference between get_posts and query_posts regarding specifying the number of posts per page?
numberposts is used instead of posts_per_page
136
Does WP_Query and query_posts accept the same parameters?
Yes
137
How do you call WP_Query to get hold of the posts?
$new_query = new WP_Query($args);
138
How do you traverse the posts, when you have called WP_Query and saved the data in a variable named $new_query?
if ($new_query->have_posts()): while($new_query->have_posts()): $new_query->the_post(); // Do stuff with normal template tags endwhile; endif;
139
How can you get access to the default query in template file?
global $query_string It is setup when WP_Query is called - and is a global variable.
140
How could you modify the existing query string in order to filter by category 5?
global $query_string; query_posts($query_string . "&cat=-5");
141
query_posts is not the most preferred, or efficient way of setting up a new query in wordpress, but it IS the best way to do what??
Modify a default query when you are already in a page template.
142
Rather than waiting till you are in the template and using query_posts to modify the query, you can use a hook to intercept the query before you get to the template. What hook would this be?
pre_get_posts, which is called after the query is built, but before the query is actually run by wordpress.
143
What are some of the caveats of using the pre_get_posts hook?
Because of the timing of when it is run, there are a few functions that are not available. For instance - is_front_page() conditional function
144
Is is_home() conditional function available in the pre_get_posts hook?
Yes
145
What does the query string "cat=-3" do?
Removes category 3 from the query.
146
In a situation where you need to run multiple queries on a single page - is it fine to use query_posts to do so?
Yes (and the codex recommends this) - BUT it does trash the main query, so it may not be ideal in many cases.
147
What is an alternative way of running multiple queries if using query_post is not an option?
You can create other instances of WP_Query and use that to get the second / third loop.
148
When creating multiple loops you should always make sure you do what...
rest the post data wp_reset_postdata()
149
Anytime you change what will be output by the template tags away from the default query, you must..
reset the query.
150
What are the three functions available for resetting the query and post data?
wp_reset_postdata() wp_reset_query() rewind_posts();
151
wp_reset_postdata is a pretty simple function that resets the tags and $post variable after you've made any custom loops - how is this function different to wp_reset_query?
It's basically the same - both are called after using any additional or custom loops, it takes no parameters - but it's designed to be used when modifying a query with the query_posts function. query_posts modifies the main query, this function counter-acts that.
152
What is the purpose of the rewind_posts function?
It resets the loop so that you can re-run a loop somewhere else in the page.
153
If you want to run a secondary loop just to get some post titles, which function can be a good option?
get_posts
154
How would you setup the arguments to WP_Query to get posts that are in cats 2, 6 and ordered by title in decending order?
``` $args = array( 'post_type' => 'posts', 'orderby' => 'title', 'order' => 'desc', 'category__and' => array(2, 6), ); $new_query = new WP_Query($args); ```
155
How would you setup a query using WP_Query to get posts which are in the category sci-fi, and included actors Matt LeBlanc and Heather Graham?
``` $args = array( 'post_type' => 'review', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'sci-fi', ), array( 'taxonomy' => actor', 'field' => 'slug', 'terms' => array('Matt LeBlanc', 'Heather Graham'), 'operator' => 'IN' ), ), ); $new_query = new WP_Query($args); ```
156
What type of query can you use to find posts based on custom meta data?
meta_query ``` $args = array( 'post_type' => 'any', 'meta_key' => 'title', 'meta_value' => 'desc', ); $new_query = WP_Query($args); ```
157
When doing custom queries, there is one feature that is no longer available - what is that?
Automatic pagination - you have to take care of this yourself. (Although, if you are only modifying the current query, you may be okay)
158
How do you implement pagination manually?
``` // Obtain the globalised $paged variable: global $paged; // Do your querying (not shown here) if (have_posts()): while(have_posts()): the_post(): ``` ``` endwhile; next_posts_link(); // This... previous_posts_link(); // and this endif; The two functions next_posts_link and previous_posts_link are used to link up the pagination. ```
159
What property of WP_Query holds then number of posts that have been found?
$post_count
160
What is the main thing to remember about WP_Query properties?
They should never be directly meddled with - use the accessors / mutators.
161
What property of WP_Query holds the actual post data that resulted from your query?
$posts
162
What property of WP_Query holds the query that was passed to the WP_Query object?
$query
163
What property of WP_Query holds an associative array containing all of the query vars and values?
$query_vars
164
What property of WP_Query holds the number of posts that resulted from your query (but ignoring any pagination data)?
$found_posts
165
What property of WP_Query holds the maximum number of pages based on the number of found posts and the pagination limit?
$max_num_pages
166
What does the following command do? global $post;
Gives access to the global $post variable which contains all the information about the current post.
167
What does the following command do? global $authordata;
Gives access to the global $authordata variable which contains all available data about the author of the current post.
168
What does the following command do? global $wp_query;
Gives access to the global $wp_query variable which contains all of the information referring to the default query. This is overwritten by query_posts - however all other functions should leave it alone.
169
What does the following command do? global $wp;
Gives access to the global $wp variable which contains all of the initialisation data relating to the current wordpress instance.
170
What does the following command do? global $wpdb;
Gives access to the global $wpdb variable which gives access to the database (especially useful for plugins).
171
What does the following command do? global $wp_rewrite;
Gives access to the global $wp_rewrite variable which holds all of the current information on what rewrite rules hold for the entire site. Used primarily for pretty permalinks.
172
What does the following command do? global $query_string;
Gives access to the global $query_string variable which holds the current query for the page.
173
What does the following command do? global $paged;
Gives access to the global $paged variable which holds the current page number, should the site be on the first page of the data, the $paged variable is set to 0.
174
What is a template tag?
It is code that instructs or tells wordpress to get something. They are basically functions. Wordpress defines a bunch of them including things like: the_author(); the_author_posts();
175
What is the bloginfo() tag?
It returns a lot of information regarding the blog - including things like the name of the blog (settings/general/page). bloginfo('name');
176
How can one use the bloginfo() tag function when making sure paths are consistent?
You can use it to get the theme directory to ensure JS / CSS folders are always referenced correctly. src="/images/logo.png"
177
What are some of the values that can be retrieved from the bloginfo() tag?
``` name - site title description wpurl - the Wordpress site url url - the url admin_email charset version - version of wordpress stylesheet_directory template_directory ```
178
What class of tags are probably the most used?
``` The post tags. I.e. functions such as: the_title the_content the_excerpt the_title_attribute (i.e. title without html tags) ```
179
When would you tend to use the function | the_title_attribute()?
When you want to use the title of the post without the html tags and all the characters correctly encoded. A good example might be in a "title" element of a link.
180
What is the main template tag for displaying all the comments attached to a post?
wp_list_comments
181
wp_list_comments allows customisation of the output, how do you do this?
``` You pass an array with configuration options. $options = array( 'style' => 'ul', 'per_page' => '10', 'avatar_size' => '50', ); wp_list_comments($options); ```
182
There are two type of category tags in wordpress, what are they?
Ones that return categories in relation to the current post, and ones that return data on the categories in general.
183
What does the_category tag do?
It is used in the loop to output the categories that the current post belongs to.
184
What tag is used to list all of the categories on a site?
wp_list_categories
185
How do you customise the output that wp_list_categories has?
``` $args = array( 'orderby' => 'count', 'order' => 'ASC', 'style' => 'list', 'show_count' => 1, 'hide_empty' => 0, 'title_li' => '', 'number' => 10, 'depth' => -1, ); wp_list_categories($args); ```
186
What is one thing to keep in mind when using wp_list_categories (regarding formatting of output)?
The list (depending on settings) may be given within a bunch of li tags, you have to provide your own ol or ul tags to wrap it.
187
The author tags do what?
Provide information on the author of a post, or on the website etc. NOTE: This is not related to the Wordpress role of Author.
188
What tag can be used to get all of the posts by the Author (and hence we could create a link - "all posts by this author")?
the_author_posts_link
189
What are link tags?
Essentially any tags that interact with a link in some form or other. It may return a link or link. For instance get_permalink or the_permalink. Even functions such as next_posts_link() - which is used for pagination.
190
Instead of using a simple '/' for the logo link to return to the homepage, what tag you use instead (to prevent any issues relating to paths / config)?
home_url();
191
What template tag would you use to print out a custom menu?
wp_nav_menu()
192
wp_nav_menu requires the parameter, 'theme_location' which must also have an attribute defined in the theme. How do you do this?
In your functions.php file register the menu: register_nav_menus(array( 'primary' => __('Primary Menu', 'prowordpress'), ); ``` // To be able to access the menu in your templates through // the wp_nav_menu function wp_nav_menu(array('theme_location' => 'primary', 'container' => '')); ```
193
What does the container parameter do in wp_nav_menu arguments array? wp_nav_menu(array('theme_location' => 'primary', 'container'=>''));
It allows you to define what kind of container the function will return the menu in. I.e. you could pass it 'div' and it will be wrapped in a div. You can leave it empty if you want to control this yourself in the template.
194
What is the rule relating to where you can use post-specific tags and general tags?
General tags can be used anywhere you need the information, inside or outside of the loop. However, post specific tags MUST be used within the loop.
195
What location-specific tags exist (i.e. which type of tags must be used only within the loop)?
Post-specific tags Comment-specific tags (There are some exceptions, as there are some tags that will take post-id's allowing them to be used outside of the loops).
196
Generally a tag that begins with the word 'the_' will output...
HTML - i.e.: the_title the_content the_permalink
197
Tags that must the 'echo' command in order to be output generally have what in the name?
get_ i.e. get_the_title get_the_content get_permalink
198
Name two functions that would appear to have to be used within a loop, but can in fact be used outside?
get_the_title get_permalink Both can take a post ID allowing them to be used outside the loop.
199
Does the tag 'the_date' return the data in HTML or require using echo to output it?
Can be either, it takes a parameter that allows the user to choose.
200
Template tags take arguments as either Arrays or Query strings - true or false?
False - it depends on the function. General rule of thumb is a tag with very few parameters will take the arguments as PHP style parameters. A tag with a large number of parameters will take the arguments as either an array or a query string. You really have to check the codex to be sure.
201
How do you ensure that your site uses the SSL certificate for ADMIN pages?
In wp-config.php place the following line: define('FORCE_SSL_ADMIN', true);
202
What is the purpose of body_class and post_class functions?
They output class information for the page which can be used by CSS to style the page.
203
What does: post_class(); output?
class="post-565 page type-page status-publish hentry"
204
How can you add additional class types to the output of post_class?
Simply pass them as parameters | post_class("custom-page unique-styles");
205
What part of the wordpress api would you use to add category ID's to the post_class, or body_class output?
The hook api. i.e. add_filter('post_class', 'add_category_class'); Where add_category class is a function that returns the current posts category formatted for use in the class string.
206
What class is returned by post_class that is useful for styling sticky posts?
sticky
207
What is the issue with using the post-id as an identifier in the class field?
If you are using local dev environments, it is unlikely that the data will save in the same order, giving you different potential ID's for your posts. Use post slugs instead - they tend to be more reliable.
208
What defines the name of a theme?
The meta data in the style.css file (part of the theme).
209
What does the HTML 'aside' tag do?
It is information that should be considered separate (yet related) to the surrounding content. It could be things like a glossary, author biography etc.
210
When paginating a page of posts, how would you pass a custom "lable" to the next button?
next_posts_link("Past news");
211
What does wp_get_archives do?
Displays the archives of your posts by date. So you can have a monthly breakdown of your posts in a side bar with all the posts associated with the appropriate months.
212
Links generated by wp_get_archives is handled by which template?
archive.php
213
What does single_cat_title() do?
Returns the page title, if a category or tag archive is queried. Can only be used outside of the loop.
214
If you need to get the title of a page before you (and must use conditionals to determine what the title will be) what can you do?
Just call the_post() once - determine what the title should be (you can use functions like is_category, is_tag etc to work it out). Then use single_tag_title or single_cat_title to get the title. Just note: When you get to the while loop, you will already be on the second post - so make sure you call rewind_post to reset the counter before you start your loop.
215
What does the wp_list_pages function do?
It lists a list of the wordpress pages as a set of links. It can take the id of the current page and only list sub pages if required.
216
What does wp_nav_menu do, and what must you do in order to use it?
It displays a navigation menu. If you pass it (via the args) the id/name of a menu, ("theme_location" parameter), it will display the menu assigned to that location. If you use the function, you have to register the menu in the functions.php file. register_nav_menus(array( 'primary' => __('Primary menu', 'prowordpress') ));
217
If your theme has a lot of things to register / do in the functions.php file, what is a common way to deal with this?
Stick it all in a theme_setup style function and register to fire on a hook. function mytheme_setup() {} add_action('after_setup_theme', 'mytheme_setup');
218
A custom post type should be used when?
When you have a series of content to be grouped in one way or another. All content should conform to the same format and page structure and generally revolve around the same theme. i.e. (Products, movies, books. events, testimonials, staff) - generally displayed in a list, with a possible drill down into a single page.
219
How does Wordpress expect custom post types to be named?
All lowercase, use a prefix (or namespace), use underscores to separate words. i.e. For Pro Themepress Development you might use: ptd_event NOTE: The convention is usually (but not exclusively) to use a single word to describe the post type (i.e. event, post etc) Also - keep them singular - it's not until they are grouped on the page that they are plural.
220
What are the two methods for creating a custom post type?
You can create it as a custom plugin or just use the themes function file. The decision depends on whether you are intending to use the post type in many themes (plugin) or if it is intended to be used just with this theme (functions file - to prevent a user having to download the plugin as well as the theme).
221
What function is used to register a custom post type?
register_post_type
222
Can you set a custom post type to have it's own archive?
Yes - the has_archive option can be set to 'true' meaning that it will have it's own archive.
223
What does __( ) mean?
It is an alias to the translate() function. It takes two parameters, the text to translate, and the text domain.
224
The register_post_type function should be called early in the setup process, how can you make sure this occurs?
Wrap the calls to register_post_type in a container function then use a hook on the "init" action. add_action('init', 'new_post_types');
225
In the register_post_type arguments, there is a way to configure all of the "labels" associated with the post (i.e. messages and button labels etc), how do you do this?
Create an array with a key / value pair defining each of the labels, then assign this array to the key "labels", in the $args array that is passed to register_post_types
226
When should you use the __() function?
Pretty much anytime there is text that your user may see - it allows you to easily configure the site
227
What register_post_type parameters control where the post types are shown in the admin area?
``` public public_queryable exclude_from_search show_ui show_in_menu show_in_nav_menu show_in_admin_bar menu_position ```
228
The publicly_queryable option in register_post_type defines what?
Whether the theme can query any of the posts of that particularly type. This should generally be set to true, otherwise you can see the posts.
229
What is one reason you may want to set the publicly_queryable setting to false?
You could use a custom post to track orders in a shop - by setting it to false, it would not be displayed on the front end.
230
What does exclude_from_search parameter in the register_post_type function do?
Prevents searching for the post from the front end - this even prevents taxonomy based filters from showing the posts.
231
What does the show_ui parameter in the register_post_type function do/
It determines whether an admin UI element will be shown.
232
What do the parameters show_in_nav_menus and show_in_admin_bar do in the register_post_type function?
The first one determines whether the post type will be shown custom menus, and the second one determines whether it will be visible in the drop down bar in the admin screen (i.e. create new/movie)
233
What does the show_in_menu parameter in the register_post_type function do?
It determines whether the post type will be shown in the left hand admin menu. Note: rather than passing a boolean, it is possible to pass a string, which tells wordpress to put the menu option as a submenu in one of the left hand post types.
234
What does the menu_position parameter in the register_post_type function do?
It decides where in the admin menu the new post type will appear. The value is split into ranges 5: below posts 10: below media 15: below links 20: below Pages 25: below comments etc. The default is to appear below the comments menu
235
The 'supports' parameter in the register_post_type function takes an array for the value. What does this option do?
Describes the features that you want to be able to use in the post type. The defaults are title and editor. title: default post title field editor: main post content editor author: set an author for the post thumbnail: add post thumbnail support excerpt: add an excerpt field trackbacks: recognise trackbacks custom-fields: have the wordpress built in custom fields added to it comments: enable the post to have comments revisions: enable the post to track and keep revisions page-attributes: give the post type page attributes such as post order and page template page-formats: add post format selectors to the post type
236
How do you add the 'supports' parameters?
'supports' => array('title', 'editor', 'author'), Notice, you don't have to specify true false, just add the feature that you require.
237
What does the capability_type parameter in register_post_function do?
It allows you to specify what capabilities the user has over the post type, such as read, edit, delete.
238
What are custom rewrite rules (set in register_post_function)?
Provides options for how the url should be rewritten for this post type. Note: this is only available when you have pretty permalinks setup.
239
The other options in the 'rewrite' array (parameter for register_post_function) can set how wordpress should process other permalink structures. What does the option "with_front" do?
defaults to true, the permalink structure will use the front base set in the permalink settings; if this is false, it will use the slug only.
240
The other options in the 'rewrite' array (parameter for register_post_function) can set how wordpress should process other permalink structures. What does the option "feeds" do?
defaults to has_archive setting. If set to true, wordpress will generate a feed permalink structure for the post type.
241
The other options in the 'rewrite' array (parameter for register_post_function) can set how wordpress should process other permalink structures. What does the option "pages" do?
defaults to true, if set to true, wordpress will accomodate the pagination permalink structure for the post type (i.e. /move/page/2)
242
The other options in the 'rewrite' array (parameter for register_post_function) can set how wordpress should process other permalink structures. What does the option "ep_mask" do?
default (not set), takes an endpoint mask to be used for the post type.
243
When you are creating a custom post type / setting custom rewrite structures, you need to tell wordpress that you've made these changes - this can occur when activating new post types (i.e. activating a theme that contains them, or originally setting them up), how do you do this?
Call the function: flush_rewrite_rules();
244
It's best not to run flush_rewrite_rules all the time, how can you make sure it only runs when a plugin or theme is loaded?
``` Use a hook: add_action('after_switch_theme', 'cm_flush_rewrite_rules'); function cm_flush_rewrite_rules() { flush_rewrite_rules(); } ``` NOTE: This is more appropriate for adding custom post types as part of a theme. In that case, you need to create the custom post type when it is activated / deactivated. (see Pro WP Themes Development book)
245
Can you run flush_rewrite_rules at any time on your site?
You can - but shouldn't - it's really memory intensive. Make sure you use a hook to only run it when it should be run.
246
How would you create a custom menu icon for the custom post type?
'menu_icon' => bloginfo('template_directory') . '/images/movie-menu-icon.png', The icon should be 16x16px.
247
What does the option query_var do in register_post_function?
It allows you to set the variable that is used in the query search string, i.e. if you set it to movie: website.com/?movie=clerks However, you would idealy use a custom rewrite... website.com/movie/clerks which means this option isn't terribly useful.
248
What hook should you use to update the post messages (i.e. interface messages in the admin panel for a custom post)?
You can grab the post_updated_messages hook - pass it a function with all the settings (an array) - one benefit - you can do ALL of your custom posts in one call - just pass it different arrays indexed by the custom post identifier.
249
How do you add help text to the admin panel?
You can hook into the contextual_help hook.
250
How would you determine what page you are on so you know what contextual help to feed the page?
function cm_add_help_text($contextual_help, $screen_id, $screen) { if ('ptd_movie' == $screen->id) { $contextual_help = "put your help here..."; } elseif ('edit-ptd_movie' == $screen->id) { $contextual_help = "Put other stuff here..."; } }
251
Is it possible to add tabs to the help content in wordpress?
Yes, within your function for setting up the help text: $screen = get_current_screen(); $screen->add_help_tab(array( --- settings)); NOTE: This should not be called on the contextual_help hook - you should do it on the admin_head hook - otherwise you will overwrite the settings from the contextual_help call.
252
Why are custom icons for custom posts coloured, while the others are greyscale?
Wordpress adds custom icons as an img tag - whereas the inbuilt wordpress icons are controlled by css.
253
Custom post type icons may require up to 10 icons, why is this?
There are a number of different locations / styles that the icons have to cover. The grayscale, the colour, the 16px size and the 32px size (for bigger icon display, plus for high DPI screens) - and there is also a blue admin theme that you may have to support too which tints the icons blue.
254
In order to update the custom post type icons to look correct, you may have to adjust the CSS for the admin area - how would you do this?
You can create a function that returns the css in a style tag, and pass it to the admin_head function (i.e. create a custom admin_head function, and use add_action to pass it to the admin_head hook. However, it may be better to use a separate css file. add_action('admin_enqueue_scripts', 'my_admin_theme_style'); ``` function my_admin_theme_style() { wp_enqueue_style('ptd-admin-theme', get_bloginfo('template_directory') . '/css/admin-style.css'); } ```
255
How do you view a custom post type in the theme?
In a very similar way to any other post - you use a WordPress query, such as WP_Query. $args = array('post_type' => 'ptd_movie', 'posts_per_page' => 10, 'orderby' => 'title', 'order' => 'ASC', ); $movies = new WP_Query($args); // Do standard wordpress loop
256
Rather than creating a specific set of arguments to get the custom post type using WP_Query, it is possible to add a custom post type to the default query? How?
You can use the preg_get_posts hook. You will link a function to this hook that sets a query for the specific post type. (See book Pro Theme Development). This would ensure that a home page would intermingle the custom post types with the standard post types.
257
What is WP_Query::set() and when should it be used?
It's a method (non-static) that is used to modify the options win a WP_Query object. It should be used when modifying an already built query.
258
If we have a custom post type with the id ptd_movie, who would you create the template files for generating the single post and the archive pages for this post type?
Create two files called: archive-ptd_movie.php single-ptd_movie.php
259
If you were to add a new template for a a custom post type, and wordpress doesn't recognise it, what is one thing you can try?
Change your permalink settings, save it, then return it to the way it was and resave it.
260
What are the three main functions used to add additional functionality to custom, or standard post types?
add_post_type_support() remove_post_type_support() post_type_supports()
261
What hook would you use to add new functionality to a post?
Probably the "init" hook. add_action('init', 'my_func_to_add_feature');
262
Why is post_type_supports useful?
You can use it to make sure the content you are going to request exists for the current post type. if (post_type_supports('ptd_movie', 'excerpts')) { the_excerpt(); }
263
What two hooks can you use to construct additional columns in the post overview screen (in admin)?
manage_{customPostTypeName}_posts_columns | manage_{customPostTypeName}_posts_custom_column
264
When creating an additional column, you create a function that returns a set of arguments to configure the column, then fire it off on one of the available hooks. But what is the only field that is mandatory, and what does it do?
The 'cb' field. It should look like: 'cb' => '', It is required to allow the field to work with the checkbox at the top of the grid (i.e. the select all button).
265
How would you add a custom post type to wordpress's RSS feed?
Use the 'request' hook, and in the function you pass it, check that the current request is for a feed.
266
When setting up interaction messages for a custom post type, do you need both a singular and a plural version of the post title?
Just singular, since the interactions typically only talk about a single post.
267
What function do you use to create a custom taxonomy?
register_taxonomy() Hook it into the 'init' hook.
268
Can taxonomies be directly linked to a post type (i.e. part of the post type menu options)
Yes, by using the register_taxonomy function you can make the custom taxonomy part of the post type in the admin area. This will allow you to edit or add genres from this panel.
269
What is the purpose of the _x() function?
Like __() it is used in translation. However, _x() allows for provision of a context. In some languages the context changes the translation.
270
In order to allow your custom taxonomy to work like the wordpress "tags" feature, you would need to ensure you....
You must pass the parameter _update_post_term_count to the function update_count_callback
271
What are the two main ways you can display posts based on related taxonimies?
You can either create a custom wordpress query, or through custom urls with custom page templates to catch and display the content uniquely.
272
How do you setup a query for a taxonomy?
``` 'tax_query' => array( array( 'taxonomy' => 'ptd_genre', 'field' => 'slug', 'terms' => 'comedy' ) ), ```
273
When setting up the tax_query parameter for a taxonomy query, there is a field we send called "field" - what does this do?
It describes which field we should be doing the query on. It can either by the ID, or the slug. The slug is the one you want to use if you want to do a text search.
274
How would you setup a query to a taxonomy and include a relationship between the two queries?
You can use the relation operator / field: ``` 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'ptd_genre', 'field' => 'slug', 'terms' => array('horror', 'thriller', 'drama'), 'operator' => 'NOT IN', ), array( 'taxonomy' => 'ptd_actor', 'field' => 'slug', 'terms' => array('Zooey-Deschanel') ) ), ```
275
What is the hiearchy of custom taxonomy templates in wordpress?
taxonomy-taxonomy_name-term_name.php.php taxonomy-taxonomy_name.php taxonomy.php index.php NOTE: The taxonomy_name is the taxonomy_identifier used when setting up the taxonomy / term slugs. i.e. taxonomy-ptd_genre-comedy.php or taxonomy-ptd_genre.php
276
How are taxonomies and the body_class function related?
The body_class function will add new classes for the custom taxonomy which allows you to use custom CSS to format and style the page. In the case of the ptd_genre taxonomy, it would look like this: tax-ptd_genre term-comedy term-3
277
What conditional function can be used to determine if a taxonomy is being displayed (on an archive page)?
is_tax -> NOTE: you can call this a number of different ways is_tax -> any taxonomy is_tax('ptd_genre') -> true whenever on any ptd_genre page is_tax('ptd_genre', 'comedy') is_tax('ptd_genre', array('comedy', 'comic-book'))
278
If you are on a single page, how could tell whether the post is related to a specific term?
has_term('comedy', 'ptd_genre'); | has_term(array('comedy', 'horror'), 'ptd_genre');
279
wp_list_categories can be used to get a list of taxonimies, how would you do that?
You pass as an argument and array that defines how the data should be output. One of the fields (which is different when just getting all categories) is "taxonomy": ``` $args = array ( 'taxonomy' => 'ptd_genre', 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 0, 'title_li' => '', 'depth' => 1 ); ```
280
What is an alternative to using wp_list_categories to get custom taxonomy information?
You can use get_terms ``` $args = array( 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 0, 'title_li' => '', 'depth' => 1 ); $genres = get_terms("ptd_genre", $args); ```
281
What is the difference between how wp_list_categories and get_terms return data?
get_terms return the terms as objects as opposed to a print out (i.e. wp_list_categories prints the data to std out).
282
How do you get the currently queried object on a page, and what do you find in this object?
You use get_queried_object() if you're on a single post, it will return the post object if you're on a page, it will return the page object if you're on an archive page, it will return the post type object if you're on a category archive, it will return the category object if you're on an author archive, it will return the author object etc etc.
283
How would you get the current term on a taxonomy archive page?
You can use get_queried_object ``` $term_id = get_queried_object()->term_id; $current_term = get_term($term_id, "ptd_genre"); ```
284
How would you generate a tag cloud for the current taxonomy?
wp_tag_cloud(array('taxonomy' => 'ptd_genre'));
285
How would you get a list of the associated terms with a post?
the_terms(get_the_id(), 'ptd_genre');
286
How can you customise the output of the function "the_terms" such that it produces a list starting with "Genre:" and each term seperated by a forward slash?
the_terms(get_the_id(), 'ptd_genre', 'Genre: ', ' / ');
287
What function works the same as "the_terms", but returns the values as PHP strings?
get_the_term_list
288
What does the get_the_terms function do?
similar to get_terms, it takes an id and the taxonomy name as parameters - and returns objects, but only for the associated terms for the post.
289
Where do you find the custom fields option?
In the "new post" page under "Screen options".
290
Custom values are stored as...
"key / value" pairs
291
Should custom value "keys" be used for multiple posts?
Yes, the values are what changes.
292
How would you retrieve all of the meta data on a post (i.e. custom fields)?
the_meta(); returns html.
293
What api functions exist in order to manipulate and add custom fields to the system?
add_post_meta update_post_meta get_post_meta delete_post_meta
294
What database table stores the data in the custom fields?
wp_metadata
295
What are the four main database fields that are important to a custom field?
meta_id post_id meta_key meta_value
296
In the add_post_meta function, it takes four parameters - post_id, meta_key, meta_value and unique (boolean). What does Unique do?
If it is set to true, it will return false, and not change anything if a meta_key and meta_value with same value exists. However, if it is set to false, it will simply update the database with a new entry, regardless of whether a meta data with that key for the post currently exists.
297
When you add a custom field via the api - it becomes publicly available in the drop down list for the custom fields for all posts - how do you prevent this?
Create the name with an underscore for a prefix. i.e. | _private_custom_field
298
How do you delete meta data from a post using the API?
delete_post_meta($post_id, $meta_key, $meta_value); $meta_value is optional - if it is present, it will only delete records that match the $meta_value.
299
How do you access the meta value from the database, given a post id and a meta key?
get_post_meta($post_id, $meta_key);
300
If you receive a "template is missing" error on your child them, what could this be related to?
If the style.css file has spaces between the word "Template" and the colon, you will get this error. "Template :" must be "Template:"
301
What function is used to add a meta box to a webpage?
add_meta_box
302
What is a meta box?
It is a toolbox that can be added to a theme to allow a user (in the admin section) to tweak options related to a plugin / theme.
303
One of the parameters to add_meta_box ($post_type) specifies which post type the metabox should be visible. But it only takes one string (one post type) as a parameter, how do you make it appear on multiple post types?
You have to call add_meta_box multiple times.
304
What is a nonce field?
A security feature where a secret value is stored in a hidden field - it is used to validate forms to ensure they came from the right place and not some other server.
305
How do you create a form nonce?
wp_nonce_field(plugin_basename(__FILE__), 'ptd_movie_meta_noncename');
306
When setting up fields in the form, what HTML attribute can you use to make sure everything gets it's own line?
The paragraph tag
307
What should you keep in mind about html classes when creating admin forms?
There are a lot f built in classes from WP - you should use these in order to keep your UI consistent with the rest of the admin panel.
308
What does the esc_attr function do?
When you are outputting current value of metadata, for instance into a form to prefill the fields, it encodes the values into HTML entities.
309
What hook should you use to save the meta data a user has entered into an admin post?
The save_post hook
310
Why might you want to avoid saving meta data during an autosave?
The meta data routines hit the database a lot - it's probably best to avoid. You can check by testing whether DOING_AUTOSAVE is defined. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; }
311
Why does wordpress documentation return the parameter passed into the function if the function returns early (but not failed)?
It appears to be nothing more than convention.
312
How might you test that a nonce was set on a form?
if (!isset($_POST['ptd_movie_meta_noncename'] ) || !wp_verify_nonce($_POST['ptd_movie_meta_noncename'], basename(__FILE__))) { return $post_id; } // Keep in mind this is not necessarily security in this case, this is essentially confirming that your function is being called as a result of a form action - otherwise the nonce wouldn't be there, and it could just be another type of save
313
There are three main functions for updating meta data, add_meta_data, update_meta_data and delete_meta_data - how would you organise a function to make sure the right call is made for the situation?
Use an if statement to check whether the data exists (if not add, it. If it does exist update it. If it no longer exists (i.e. the field is empty) then delete it.
314
What meta data variable does wordpress use to store the name of the custom page template for the current page?
_wp_page_template - you can access this by using | get_post_meta($post->ID, '_wp_page_template', true)
315
What is one way you could use taxonomy to show meta boxes?
You could have a test that checks to see if the term is relevant for the current post - and if so, turn on the meta box. if (has_term('comedy', 'ptd_genre', $post)) { add_meta_box(....); }
316
How would you use WP_Query to query for meta data?
``` WP_Query( array( 'meta_key' => 'ptd_release_year', 'meta_value' => '2000', 'meta_compare' => '>=' )); ```
317
Other than using WP_Query to directly search for a meta_key - what other method can you use to search for custom meta data?
You can use WP_Query with the meta_query option. ``` WP_Query(array( 'post_type' => 'ptd_movie', 'meta_query' => array( 'key' => 'ptd_release_value', 'value' => array(2000, 2010), 'compare' => 'BETWEEN' ), array ( 'key' => 'running_time', 'value' => 120, 'compare' => ' ```
318
What two hooks do you use to get data into an RSS feed?
Typically just the_excerpt_rss and the_content. NOTE: There used to be a "the_content_rss" but that was depcrecated in version 2.9
319
When hooking into the "the_excertp_rss or the_content" hooks, you will receive a variable which is the content - it is important to do what with this data?
You must always return it, regardless of whether you changed it or not.
320
What function can you use to retrieve a taxonomy for a particular post type?
get_taxonomies(array('object_type' => array('ptd_movie')), | 'objects');
321
the HTML tag in the header is often given the class "no-js" - what does this do?
When modernizr runs, it will covert the string no-js to js, which is used to indicate that JavaScript is available and running.
322
How can you reduce the number of HTTP requests for image files in your wordpress theme?
You can use spritesheets - CSS allows for the loading of sprite sheets.
323
What is XFN and how do you enable it in your theme?
XFN stands for XHTML Friends Network. You can enable it by adding the following code to the head of your site (in the header template) link rel="profile" href="http://gmpg.org/xfn/11" (WP Site has more info about how to implement it.