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
Q

What is code like Respond.js and Htmlshiv referred to as?

A

Pollyfil. - or Pollyfiller - because they fill the gaps in terms of code that is not present on older browsers.

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

What is a breakpoint in regards to CSS?

A

The moment where the browser layout switches between media queries, from one layout to another.

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

How do we space our min-width / max-width values so there isn’t overlap?

A

Make sure the styles min-width value is 1px higher than the max-width

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

How do you setup XAMPP security?

A

/Applications/XAMPP/xamppfiles/xampp security

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

In XAMPP - if you get writing file permissions, what do you need to do?

A

Make sure you have the Wordpress installation saved with the right user for Webserver. Under XAMPP it is likely daemon.

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

What should you install in order to obtain better developer tools?

A

Developer plugin by Automatic. This will include additional plugins.

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

What base theme can be used to start a new web theme?

A

_s or Underscores

written by automatic

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

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?

A

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.

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

In styles.css you can add tags that describe the theme - what is the restriction on this?

A

You must use the tags that are made available by Wordpress.

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

Header.php page contains all the elements that are needed at the top of each HTML page, including:

A

The doctype, opening HTML, meta and title tags. Blog info, style sheets and website navigation.

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

The content files (page etc) are..

A

scaffolding files that call the header, footer and other files based on the content type.

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

The footer.php file contains…

A

information that typically goes at the bottom of the page - including closing tags - and in some cases, the calls to footer sidebars / widgets.

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

The index.php scaffolding file is important - why?

A

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.

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

What does get_template_part do?

A

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”.

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

In order to prevent naming conflicts with the Wordpress core - what do we need to do?

A

Make sure all functions are uniquely named (Wordpress suggests either prefixing them with the theme name - or enclosing them in a class).

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

What does page.php do?

A

Scaffolding page for content, contains the “the_content” call that calls content-page.php

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

What does the search.php file do?

A

Scaffolding file where search results are shown.

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

What does the archive.php file do?

A

Scaffolding file in which archived pages are shown.

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

What does the comments.php file do?

A

Scaffolding file that is used to display comments.

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

What does the 404 file do/

A

Scaffolding file that is used to display 404 errors when files cannot be found.

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

What is the rtl.css file for?

A

It is a CSS file that is used for right-to-left languages.

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

What is the README.md file for?

A

Github readme file.

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

What is the functions.php file?

A

Add custom functions to the theme.

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

What is a Post Format?

A

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.

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

If we want to add custom JavaScript or Styles to a page - how do we do this?

A

We must use the functions.php file, and in the topcat_scripts function - call:

wp_enqueue_scripts
wp_enqueue_scripts

functions.

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

What is the difference between content-sidebar.css and sidebar-content.css?

A

content-sidebar is for sidebars on the right of the content. sidebar-content is for sidebars on the left of the content.

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

What file extension does localisation files have?

A

.pot, located in the
themes/yourthemename/languages
folder

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

What does the following JS file do in the theme JS directory directory?

skip-link-focus-fix.js

A

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.

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

What is a skip link?

A

A navigation link that is usually used to link to parts of the same page, to allow users to skip over repetitive content.

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

What goes in the “inc” folder of the theme?

A

Files that are used for extending the functionality of the theme.

Generally PHP files.

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

Does wordpress require tabs or spaces for the PHP coding standards?

A

tabs

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

Wordpress class names should use what convention?

A

Capitalised words, with underscores to separate them.

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

Which is correct for the Wordpress CSS coding standard?

h1, h2, h3 { }
or
h1,
h2,
h3 {
}
A

The second one:

h1,
h2,
h3 {
  // Do CSS stuff here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

What third party tool can be used to fix coding stanards issues with wordpress themes / plugins?

A

PHP Codesniffer

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

How do child themes allow functions to be “pluggable”?

A

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.

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

What must you do to ensure child themes work correctly?

A

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.

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

If we are planning to submit the theme to wordpress.org, what do we have to remember with regards to fonts?

A

We must include the fonts locally - and not use google.com font repository.

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

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?

A

Register the font first:

wp_register_style(‘topcat-headings-font’, get_template_directory_uri() . ‘/css/open-sans.css’);

wp_enqueue_style(‘topcat-headings-font’);

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

In style.css the “reset” section overrides a number of settings - why?

A

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.

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

Is the “reset” section in style.css meant to be changed?

A

no - in general it should be left as is.

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

How do you configure the tagline?

A

Settings | General | Tagline

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

What does the body_class function do?

A

It inserts the given classes into the body tag of the html based on where you are in the WP hiearchy.

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

What is the difference between the functions “the_title()” and “get_the_title”?

A

the_title will echo the title of the page out directly into HTML. get_the_title returns the title string.

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

Why does wordpress sometimes use query strings to pass data to functions?

A

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.

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

What is the Yoda condition?

A

Putting the comparison variable on the right of an equality test to ensure you don’t accidentally use an assignment operator.

if (true === $theForce)

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

What are the naming conventions for Wordpress?

A

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.

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

What must be done with regards to HTML?

A

HTML code must pass validation of the W3C validator. All tags must be closed.

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

What does the constant WP_DEBUG_LOG do?

A

If set to true, stores all errors warnings and notifications in a debug.log file in wp-content folder.

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

What does WP_DEBUG_DISPLAY do?

A

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.

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

What does the constant SCRIPT_DEBUG do?

A

Makes the wordpress environment use the development styles and scripts in case you are developing anything in the admin area.

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

What does the constant SAVEQUERIES do?

A

When set to true, saves all queries to the database as well. Causes heavy performance issues - but useful for debugging.

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

Wordpress theme names should never include any…

A

numbers - or else it wont be shown in the theme browser.

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

What is the absolute bare minimum number of files that can be in a theme?

A

index. php

style. css

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

What needs to be at the top of the style.css file?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

How do you add a screenshot to your theme?

A

Use an image of 600x450px, and call it screenshot.png. Place it in the root of the theme folder.

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

What are the basic template files that can be used to build a theme?

A

header. php
footer. php
sidebar. php
comments. php
searchform. php

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

What does the wp_title function do?

A

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.

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

Which function holds the data required to display the admin bar when a user is logged in?

A

wp_footer()

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

If there is a 30px space at the top of your site, what have you likely forgot?

A

wp_footer() function

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

Is a comments.php template required in your theme?

A

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.

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

Is a searchform.php template required in your theme?

A

No - wordpress provides a default one if there isn’t one in your theme.

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

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?

A
get_header()
get_footer()
get_sidebar()
get_search_form()
comments_template()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

get_header, get_footer and get_sidebar can all be passed a string, what does that do?

A

You can specify an alternative template other than the default to use.

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

How would you specify a different sidebar to be used on specific pages?

A

Create a file called sidebar-secondary.php, then call it in the template you want to use it in like this:

get_sidebar(‘secondary’);

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

comments_template(), like get_header, can take a parameter specifying a special template - but what is different about it from get_header?

A

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.

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

What is the purpose of the functions.php in wordpress?

A

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

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

What does add_theme_support function do?

A

Adds support for certain features available within Wordpress to the theme.

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

What is the list of features that can be added via add_theme_support function?

A
post-formats
post-thumbnails
custom-background
custom-header
automatic-feed-links
html5
title-tag
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

What does the theme support “posts-formats” provide?

A

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.

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

Can new post-formats be added to wordpress?

A

No, not through themes or even plugins.

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

What does the theme support for posts-thumbnails provide?

A

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.

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

What does the theme support for html5 provide/

A

Allows the use of HTML5 markup in search forms, comment forms, galleries and captions.

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

What does the theme support for title tag do?

A

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.

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

How would you create a template for an about page?

A

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

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

What is single.php template for?

A

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.

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

What page is used if you link to post attachments?

A

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

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

When is the archive.php file used?

A

It is used whenever a group of posts or information is being accessed through a query.

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

What pages can override the archive.php file?

A

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

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

When is the front-page template used in WP?

A

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.

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

When is the home.php template used?

A

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.

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

What is the search.php page used for?

A

Displays the results of any search performed on the site.

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

What url do you have to call to perform a search?

A

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.

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

What function fetches the search results?

A

the_search_query();

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

The 404.php template is displayed by PHP when…

A

it can’t find the result for a query, a specific page, or post.

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

How do you create a custom page template?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
110
Q

What is a post format?

A

It’s a way of adding meta data to a post allowing more specific formatting and styling in a theme.

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

By default post types can be used for posts and custom post types, to add post formats to pages, you need to…

A
call add_post_type_support
// Add post-formats to post_type 'page'
add_post_type_support('page', 'post-formats');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
112
Q

How can I test whether a post has a specific post format?

A

if (has_post_format(‘video’)) :

endif;

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

How would you get the post format as a string?

A

$format = get_post_format($post_id);

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

What is the most common way to get the post format?

A

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.

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

How does get_template_part work?

A

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.

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

What is a good directory structure for a theme?

A

/ - 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

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

wp_register_style
wp_register_script

These functions are used for…

A

Tells WP that a style or script is available for use, and gives them a handle.

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

wp_enqueue_style
wp_enqueue_script

These functions are used for…

A

Used to add the style sheet to a generated WP page through either wp_head, or wp_footer

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

What does add_action function do?

A

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.

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

What function do you use to include a style sheet/

A

wp_enqueue_style

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

Which action hook should you use to load scripts and styles that are meant to be viewed on the front end?

A

wp_enqueue_scripts

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

Does WP_Query make database calls?

A

Not itself no, it acts as a gateway.

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

What are the two main things that happens in the main index.php file for Wordpress?

A

Themes are enabled
define(‘WP_USE_THEMES’, true);
and the wordpress environment is loaded:
require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ );

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

Which file is responsible for setting up wordpress, making the database connections etc?

A

wp-load.php

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

How are have_posts and the_post related to WP_Query/

A

They are functional wrappers around that class.

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

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)?

A

It calls rewind_posts() so that Wordpress is ready to setup another loop should it need to.

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

What does the_post do?

A

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.

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

Do you need to loop everytime when setting up posts?

A

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.

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

What are the three functions that WP gives you to customise a query?

A

query_posts
get_posts
WP_Query

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

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.

A
query_posts(
    'cat' => 5,
    'posts_per_page' => 2,
    'order' => 'ASC'
);
131
Q

How would you loop through the results of a call to query_posts?

A

query_posts(“cat=5”);
if (have_posts()): while(have_posts()):the_post();
// Do stuff
endwhile; endif;

132
Q

Other than calling query_posts, how else can you retrieve the posts?

A

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
Q

Do you need to use setup_postdata() in a loop when using get_posts to get the posts?

A
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
Q

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?

A
// Raw
echo $post->post_content;
// Formatted
echo apply_filters('the_content', $post->post_content);
135
Q

What is one difference between get_posts and query_posts regarding specifying the number of posts per page?

A

numberposts is used instead of posts_per_page

136
Q

Does WP_Query and query_posts accept the same parameters?

A

Yes

137
Q

How do you call WP_Query to get hold of the posts?

A

$new_query = new WP_Query($args);

138
Q

How do you traverse the posts, when you have called WP_Query and saved the data in a variable named $new_query?

A

if ($new_query->have_posts()): while($new_query->have_posts()): $new_query->the_post();

// Do stuff with normal template tags

endwhile; endif;

139
Q

How can you get access to the default query in template file?

A

global $query_string

It is setup when WP_Query is called - and is a global variable.

140
Q

How could you modify the existing query string in order to filter by category 5?

A

global $query_string;

query_posts($query_string . “&cat=-5”);

141
Q

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??

A

Modify a default query when you are already in a page template.

142
Q

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?

A

pre_get_posts, which is called after the query is built, but before the query is actually run by wordpress.

143
Q

What are some of the caveats of using the pre_get_posts hook?

A

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
Q

Is is_home() conditional function available in the pre_get_posts hook?

A

Yes

145
Q

What does the query string “cat=-3” do?

A

Removes category 3 from the query.

146
Q

In a situation where you need to run multiple queries on a single page - is it fine to use query_posts to do so?

A

Yes (and the codex recommends this) - BUT it does trash the main query, so it may not be ideal in many cases.

147
Q

What is an alternative way of running multiple queries if using query_post is not an option?

A

You can create other instances of WP_Query and use that to get the second / third loop.

148
Q

When creating multiple loops you should always make sure you do what…

A

rest the post data

wp_reset_postdata()

149
Q

Anytime you change what will be output by the template tags away from the default query, you must..

A

reset the query.

150
Q

What are the three functions available for resetting the query and post data?

A

wp_reset_postdata()
wp_reset_query()
rewind_posts();

151
Q

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?

A

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
Q

What is the purpose of the rewind_posts function?

A

It resets the loop so that you can re-run a loop somewhere else in the page.

153
Q

If you want to run a secondary loop just to get some post titles, which function can be a good option?

A

get_posts

154
Q

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?

A
$args = array(
    'post_type' => 'posts',
    'orderby' => 'title',
    'order' => 'desc',
    'category\_\_and' => array(2, 6),
);
$new_query = new WP_Query($args);
155
Q

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?

A
$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
Q

What type of query can you use to find posts based on custom meta data?

A

meta_query

$args = array(
     'post_type' => 'any',
     'meta_key' => 'title',
     'meta_value' => 'desc',
);
$new_query = WP_Query($args);
157
Q

When doing custom queries, there is one feature that is no longer available - what is that?

A

Automatic pagination - you have to take care of this yourself. (Although, if you are only modifying the current query, you may be okay)

158
Q

How do you implement pagination manually?

A
// 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
Q

What property of WP_Query holds then number of posts that have been found?

A

$post_count

160
Q

What is the main thing to remember about WP_Query properties?

A

They should never be directly meddled with - use the accessors / mutators.

161
Q

What property of WP_Query holds the actual post data that resulted from your query?

A

$posts

162
Q

What property of WP_Query holds the query that was passed to the WP_Query object?

A

$query

163
Q

What property of WP_Query holds an associative array containing all of the query vars and values?

A

$query_vars

164
Q

What property of WP_Query holds the number of posts that resulted from your query (but ignoring any pagination data)?

A

$found_posts

165
Q

What property of WP_Query holds the maximum number of pages based on the number of found posts and the pagination limit?

A

$max_num_pages

166
Q

What does the following command do?

global $post;

A

Gives access to the global $post variable which contains all the information about the current post.

167
Q

What does the following command do?

global $authordata;

A

Gives access to the global $authordata variable which contains all available data about the author of the current post.

168
Q

What does the following command do?

global $wp_query;

A

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
Q

What does the following command do?

global $wp;

A

Gives access to the global $wp variable which contains all of the initialisation data relating to the current wordpress instance.

170
Q

What does the following command do?

global $wpdb;

A

Gives access to the global $wpdb variable which gives access to the database (especially useful for plugins).

171
Q

What does the following command do?

global $wp_rewrite;

A

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
Q

What does the following command do?

global $query_string;

A

Gives access to the global $query_string variable which holds the current query for the page.

173
Q

What does the following command do?

global $paged;

A

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
Q

What is a template tag?

A

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
Q

What is the bloginfo() tag?

A

It returns a lot of information regarding the blog - including things like the name of the blog (settings/general/page).

bloginfo(‘name’);

176
Q

How can one use the bloginfo() tag function when making sure paths are consistent?

A

You can use it to get the theme directory to ensure JS / CSS folders are always referenced correctly.

src=”/images/logo.png”

177
Q

What are some of the values that can be retrieved from the bloginfo() tag?

A
name - site title
description
wpurl - the Wordpress site url
url - the url
admin_email
charset
version - version of wordpress
stylesheet_directory
template_directory
178
Q

What class of tags are probably the most used?

A
The post tags. I.e. functions such as:
the_title
the_content
the_excerpt
the_title_attribute (i.e. title without html tags)
179
Q

When would you tend to use the function

the_title_attribute()?

A

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
Q

What is the main template tag for displaying all the comments attached to a post?

A

wp_list_comments

181
Q

wp_list_comments allows customisation of the output, how do you do this?

A
You pass an array with configuration options.
$options = array(
   'style' => 'ul',
   'per_page' => '10',
   'avatar_size' => '50',
);
wp_list_comments($options);
182
Q

There are two type of category tags in wordpress, what are they?

A

Ones that return categories in relation to the current post, and ones that return data on the categories in general.

183
Q

What does the_category tag do?

A

It is used in the loop to output the categories that the current post belongs to.

184
Q

What tag is used to list all of the categories on a site?

A

wp_list_categories

185
Q

How do you customise the output that wp_list_categories has?

A
$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
Q

What is one thing to keep in mind when using wp_list_categories (regarding formatting of output)?

A

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
Q

The author tags do what?

A

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
Q

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”)?

A

the_author_posts_link

189
Q

What are link tags?

A

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
Q

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)?

A

home_url();

191
Q

What template tag would you use to print out a custom menu?

A

wp_nav_menu()

192
Q

wp_nav_menu requires the parameter, ‘theme_location’ which must also have an attribute defined in the theme. How do you do this?

A

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
Q

What does the container parameter do in wp_nav_menu arguments array?
wp_nav_menu(array(‘theme_location’ => ‘primary’, ‘container’=>’’));

A

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
Q

What is the rule relating to where you can use post-specific tags and general tags?

A

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
Q

What location-specific tags exist (i.e. which type of tags must be used only within the loop)?

A

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
Q

Generally a tag that begins with the word ‘the_’ will output…

A

HTML - i.e.:
the_title
the_content
the_permalink

197
Q

Tags that must the ‘echo’ command in order to be output generally have what in the name?

A

get_ i.e.
get_the_title
get_the_content
get_permalink

198
Q

Name two functions that would appear to have to be used within a loop, but can in fact be used outside?

A

get_the_title
get_permalink

Both can take a post ID allowing them to be used outside the loop.

199
Q

Does the tag ‘the_date’ return the data in HTML or require using echo to output it?

A

Can be either, it takes a parameter that allows the user to choose.

200
Q

Template tags take arguments as either Arrays or Query strings - true or false?

A

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
Q

How do you ensure that your site uses the SSL certificate for ADMIN pages?

A

In wp-config.php place the following line:

define(‘FORCE_SSL_ADMIN’, true);

202
Q

What is the purpose of body_class and post_class functions?

A

They output class information for the page which can be used by CSS to style the page.

203
Q

What does:

post_class();

output?

A

class=”post-565 page type-page status-publish hentry”

204
Q

How can you add additional class types to the output of post_class?

A

Simply pass them as parameters

post_class(“custom-page unique-styles”);

205
Q

What part of the wordpress api would you use to add category ID’s to the post_class, or body_class output?

A

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
Q

What class is returned by post_class that is useful for styling sticky posts?

A

sticky

207
Q

What is the issue with using the post-id as an identifier in the class field?

A

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
Q

What defines the name of a theme?

A

The meta data in the style.css file (part of the theme).

209
Q

What does the HTML ‘aside’ tag do?

A

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
Q

When paginating a page of posts, how would you pass a custom “lable” to the next button?

A

next_posts_link(“Past news”);

211
Q

What does wp_get_archives do?

A

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
Q

Links generated by wp_get_archives is handled by which template?

A

archive.php

213
Q

What does single_cat_title() do?

A

Returns the page title, if a category or tag archive is queried. Can only be used outside of the loop.

214
Q

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?

A

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
Q

What does the wp_list_pages function do?

A

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
Q

What does wp_nav_menu do, and what must you do in order to use it?

A

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
Q

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?

A

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
Q

A custom post type should be used when?

A

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
Q

How does Wordpress expect custom post types to be named?

A

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
Q

What are the two methods for creating a custom post type?

A

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
Q

What function is used to register a custom post type?

A

register_post_type

222
Q

Can you set a custom post type to have it’s own archive?

A

Yes - the has_archive option can be set to ‘true’ meaning that it will have it’s own archive.

223
Q

What does __( ) mean?

A

It is an alias to the translate() function. It takes two parameters, the text to translate, and the text domain.

224
Q

The register_post_type function should be called early in the setup process, how can you make sure this occurs?

A

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
Q

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?

A

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
Q

When should you use the __() function?

A

Pretty much anytime there is text that your user may see - it allows you to easily configure the site

227
Q

What register_post_type parameters control where the post types are shown in the admin area?

A
public
public_queryable
exclude_from_search
show_ui
show_in_menu
show_in_nav_menu
show_in_admin_bar
menu_position
228
Q

The publicly_queryable option in register_post_type defines what?

A

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
Q

What is one reason you may want to set the publicly_queryable setting to false?

A

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
Q

What does exclude_from_search parameter in the register_post_type function do?

A

Prevents searching for the post from the front end - this even prevents taxonomy based filters from showing the posts.

231
Q

What does the show_ui parameter in the register_post_type function do/

A

It determines whether an admin UI element will be shown.

232
Q

What do the parameters show_in_nav_menus and show_in_admin_bar do in the register_post_type function?

A

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
Q

What does the show_in_menu parameter in the register_post_type function do?

A

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
Q

What does the menu_position parameter in the register_post_type function do?

A

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
Q

The ‘supports’ parameter in the register_post_type function takes an array for the value. What does this option do?

A

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
Q

How do you add the ‘supports’ parameters?

A

‘supports’ => array(‘title’, ‘editor’, ‘author’),

Notice, you don’t have to specify true false, just add the feature that you require.

237
Q

What does the capability_type parameter in register_post_function do?

A

It allows you to specify what capabilities the user has over the post type, such as read, edit, delete.

238
Q

What are custom rewrite rules (set in register_post_function)?

A

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
Q

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?

A

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
Q

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?

A

defaults to has_archive setting. If set to true, wordpress will generate a feed permalink structure for the post type.

241
Q

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?

A

defaults to true, if set to true, wordpress will accomodate the pagination permalink structure for the post type (i.e. /move/page/2)

242
Q

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?

A

default (not set), takes an endpoint mask to be used for the post type.

243
Q

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?

A

Call the function:

flush_rewrite_rules();

244
Q

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?

A
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
Q

Can you run flush_rewrite_rules at any time on your site?

A

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
Q

How would you create a custom menu icon for the custom post type?

A

‘menu_icon’ => bloginfo(‘template_directory’) . ‘/images/movie-menu-icon.png’,

The icon should be 16x16px.

247
Q

What does the option query_var do in register_post_function?

A

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
Q

What hook should you use to update the post messages (i.e. interface messages in the admin panel for a custom post)?

A

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
Q

How do you add help text to the admin panel?

A

You can hook into the contextual_help hook.

250
Q

How would you determine what page you are on so you know what contextual help to feed the page?

A

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
Q

Is it possible to add tabs to the help content in wordpress?

A

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
Q

Why are custom icons for custom posts coloured, while the others are greyscale?

A

Wordpress adds custom icons as an img tag - whereas the inbuilt wordpress icons are controlled by css.

253
Q

Custom post type icons may require up to 10 icons, why is this?

A

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
Q

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?

A

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
Q

How do you view a custom post type in the theme?

A

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
Q

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?

A

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
Q

What is WP_Query::set() and when should it be used?

A

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
Q

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?

A

Create two files called:
archive-ptd_movie.php
single-ptd_movie.php

259
Q

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?

A

Change your permalink settings, save it, then return it to the way it was and resave it.

260
Q

What are the three main functions used to add additional functionality to custom, or standard post types?

A

add_post_type_support()
remove_post_type_support()
post_type_supports()

261
Q

What hook would you use to add new functionality to a post?

A

Probably the “init” hook.

add_action(‘init’, ‘my_func_to_add_feature’);

262
Q

Why is post_type_supports useful?

A

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
Q

What two hooks can you use to construct additional columns in the post overview screen (in admin)?

A

manage_{customPostTypeName}_posts_columns

manage_{customPostTypeName}_posts_custom_column

264
Q

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?

A

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
Q

How would you add a custom post type to wordpress’s RSS feed?

A

Use the ‘request’ hook, and in the function you pass it, check that the current request is for a feed.

266
Q

When setting up interaction messages for a custom post type, do you need both a singular and a plural version of the post title?

A

Just singular, since the interactions typically only talk about a single post.

267
Q

What function do you use to create a custom taxonomy?

A

register_taxonomy()

Hook it into the ‘init’ hook.

268
Q

Can taxonomies be directly linked to a post type (i.e. part of the post type menu options)

A

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
Q

What is the purpose of the _x() function?

A

Like __() it is used in translation. However, _x() allows for provision of a context. In some languages the context changes the translation.

270
Q

In order to allow your custom taxonomy to work like the wordpress “tags” feature, you would need to ensure you….

A

You must pass the parameter _update_post_term_count to the function update_count_callback

271
Q

What are the two main ways you can display posts based on related taxonimies?

A

You can either create a custom wordpress query, or through custom urls with custom page templates to catch and display the content uniquely.

272
Q

How do you setup a query for a taxonomy?

A
'tax_query' => array(
   array(
       'taxonomy' => 'ptd_genre',
       'field' => 'slug',
       'terms' => 'comedy'
   )
),
273
Q

When setting up the tax_query parameter for a taxonomy query, there is a field we send called “field” - what does this do?

A

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
Q

How would you setup a query to a taxonomy and include a relationship between the two queries?

A

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
Q

What is the hiearchy of custom taxonomy templates in wordpress?

A

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
Q

How are taxonomies and the body_class function related?

A

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
Q

What conditional function can be used to determine if a taxonomy is being displayed (on an archive page)?

A

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
Q

If you are on a single page, how could tell whether the post is related to a specific term?

A

has_term(‘comedy’, ‘ptd_genre’);

has_term(array(‘comedy’, ‘horror’), ‘ptd_genre’);

279
Q

wp_list_categories can be used to get a list of taxonimies, how would you do that?

A

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
Q

What is an alternative to using wp_list_categories to get custom taxonomy information?

A

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
Q

What is the difference between how wp_list_categories and get_terms return data?

A

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
Q

How do you get the currently queried object on a page, and what do you find in this object?

A

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
Q

How would you get the current term on a taxonomy archive page?

A

You can use get_queried_object

$term_id = get_queried_object()->term_id;
$current_term = get_term($term_id, "ptd_genre");
284
Q

How would you generate a tag cloud for the current taxonomy?

A

wp_tag_cloud(array(‘taxonomy’ => ‘ptd_genre’));

285
Q

How would you get a list of the associated terms with a post?

A

the_terms(get_the_id(), ‘ptd_genre’);

286
Q

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?

A

the_terms(get_the_id(), ‘ptd_genre’, ‘Genre: ‘, ‘ / ‘);

287
Q

What function works the same as “the_terms”, but returns the values as PHP strings?

A

get_the_term_list

288
Q

What does the get_the_terms function do?

A

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
Q

Where do you find the custom fields option?

A

In the “new post” page under “Screen options”.

290
Q

Custom values are stored as…

A

“key / value” pairs

291
Q

Should custom value “keys” be used for multiple posts?

A

Yes, the values are what changes.

292
Q

How would you retrieve all of the meta data on a post (i.e. custom fields)?

A

the_meta();

returns html.

293
Q

What api functions exist in order to manipulate and add custom fields to the system?

A

add_post_meta
update_post_meta
get_post_meta
delete_post_meta

294
Q

What database table stores the data in the custom fields?

A

wp_metadata

295
Q

What are the four main database fields that are important to a custom field?

A

meta_id
post_id
meta_key
meta_value

296
Q

In the add_post_meta function, it takes four parameters - post_id, meta_key, meta_value and unique (boolean). What does Unique do?

A

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
Q

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?

A

Create the name with an underscore for a prefix. i.e.

_private_custom_field

298
Q

How do you delete meta data from a post using the API?

A

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
Q

How do you access the meta value from the database, given a post id and a meta key?

A

get_post_meta($post_id, $meta_key);

300
Q

If you receive a “template is missing” error on your child them, what could this be related to?

A

If the style.css file has spaces between the word “Template” and the colon, you will get this error.

“Template :” must be “Template:”

301
Q

What function is used to add a meta box to a webpage?

A

add_meta_box

302
Q

What is a meta box?

A

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
Q

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?

A

You have to call add_meta_box multiple times.

304
Q

What is a nonce field?

A

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
Q

How do you create a form nonce?

A

wp_nonce_field(plugin_basename(__FILE__), ‘ptd_movie_meta_noncename’);

306
Q

When setting up fields in the form, what HTML attribute can you use to make sure everything gets it’s own line?

A

The paragraph tag

307
Q

What should you keep in mind about html classes when creating admin forms?

A

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
Q

What does the esc_attr function do?

A

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
Q

What hook should you use to save the meta data a user has entered into an admin post?

A

The save_post hook

310
Q

Why might you want to avoid saving meta data during an autosave?

A

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
Q

Why does wordpress documentation return the parameter passed into the function if the function returns early (but not failed)?

A

It appears to be nothing more than convention.

312
Q

How might you test that a nonce was set on a form?

A

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
Q

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?

A

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
Q

What meta data variable does wordpress use to store the name of the custom page template for the current page?

A

_wp_page_template - you can access this by using

get_post_meta($post->ID, ‘_wp_page_template’, true)

315
Q

What is one way you could use taxonomy to show meta boxes?

A

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
Q

How would you use WP_Query to query for meta data?

A
WP_Query( array(
    'meta_key' => 'ptd_release_year',
    'meta_value' => '2000',
    'meta_compare' => '>='
));
317
Q

Other than using WP_Query to directly search for a meta_key - what other method can you use to search for custom meta data?

A

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
Q

What two hooks do you use to get data into an RSS feed?

A

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
Q

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?

A

You must always return it, regardless of whether you changed it or not.

320
Q

What function can you use to retrieve a taxonomy for a particular post type?

A

get_taxonomies(array(‘object_type’ => array(‘ptd_movie’)),

‘objects’);

321
Q

the HTML tag in the header is often given the class “no-js” - what does this do?

A

When modernizr runs, it will covert the string no-js to js, which is used to indicate that JavaScript is available and running.

322
Q

How can you reduce the number of HTTP requests for image files in your wordpress theme?

A

You can use spritesheets - CSS allows for the loading of sprite sheets.

323
Q

What is XFN and how do you enable it in your theme?

A

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.