Difference between revisions of "Week Twelve (MGDP2060)"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
'''NO CLASS NEXT WEEK'''. Have a happy Thanksgiving.
 
'''NO CLASS NEXT WEEK'''. Have a happy Thanksgiving.
 +
 +
Previous: [[Week Eleven (MGDP2060)]] - Next: [[Week Thirteen (MGDP2060)]]
 +
 +
== PHP code for custom post type (p. 517) ==
 +
 +
You need this code in your <code>functions.php</code> file, in order to display custom post type (such as Products):
 +
 +
<pre>
 +
function add_product_to_archives ( $wp_query ){
 +
$types_array = array ( 'post', 'product');
 +
if ( is_archive() && empty ( $query->query_vars['suppress_filters']) ) {
 +
set_query_var ('post_type', $types_array);
 +
}
 +
}
 +
 +
add_action ( 'pre_get_posts', 'add_product_to_archives');
 +
</pre>
 +
 +
The code appears on page 517 of the textbook.
 +
 +
(1) Previously, I said that you could skip this step.  This turns out to be not true: you do need to use this code in order for the <code>category.php</code> theme to work correctly.
 +
 +
(2) You can't have a second copy of the code, for a second custom post type -- if you do, the code will not work.
 +
 +
(2.a) There must be some other code which allows use of multiple custom post types, however, I don't have that code at this time.
  
 
== Contact form plugins for WordPress ==
 
== Contact form plugins for WordPress ==

Latest revision as of 14:53, 27 November 2016

This article lists topics for Week Twelve of Web Design and Development III (MGDP2060).

NO CLASS NEXT WEEK. Have a happy Thanksgiving.

Previous: Week Eleven (MGDP2060) - Next: Week Thirteen (MGDP2060)

PHP code for custom post type (p. 517)

You need this code in your functions.php file, in order to display custom post type (such as Products):

function add_product_to_archives ( $wp_query ){
	$types_array = array ( 'post', 'product');
	if ( is_archive() && empty ( $query->query_vars['suppress_filters']) ) {
		set_query_var ('post_type', $types_array);
	}
}

add_action ( 'pre_get_posts', 'add_product_to_archives');

The code appears on page 517 of the textbook.

(1) Previously, I said that you could skip this step. This turns out to be not true: you do need to use this code in order for the category.php theme to work correctly.

(2) You can't have a second copy of the code, for a second custom post type -- if you do, the code will not work.

(2.a) There must be some other code which allows use of multiple custom post types, however, I don't have that code at this time.

Contact form plugins for WordPress

To implement web forms in WordPress, use a plugin.

Many are available. See:

I like Contact Form 7 - see also Docs.

Exercises

See Week Twelve Exercises (MGDP2060).