Example code for: http://pods.io/tutorials/learning-new-tutorials-section/
<?php | |
//include a diffrent template if it the first page of tutorials post archive | |
add_filter( 'template_include', 'pods_tutorials_page_one_temp_inc' ); | |
function pods_tutorials_page_one_temp_inc( $original_template ) { | |
//get current page of posts | |
global $wp_query; | |
$page = $wp_query->query_vars['paged']; | |
if ( is_post_type_archive( 'tutorial' ) && $page == 0 ) { | |
return get_stylesheet_directory(). '/includes/tutorials-first-page.php'; | |
} else { | |
return $original_template; | |
} | |
} | |
?> |
<?php | |
//list tutorials by topic for first page of tutorials CPT page | |
function pods_tutorials_list( $ids, $heading, $dashicon ) { | |
//include only terms whose ids were set in $ids param | |
$args = array( 'include' => $ids ); | |
//get the terms matching the args | |
$terms = get_terms( 'tutorial_type', $args ); | |
//add underscores to $heading in separate var for ul id | |
$name = str_replace(' ', '-', $heading); | |
echo '<h3>'.$heading.'</h3>'; | |
echo '<ul id="tutorials-'.$name.'" class="tutorials-topics-list">'; | |
//loop through terms | |
foreach ( $terms as $term ) { | |
//get link, description and name for each term. | |
$link = get_term_link( $term ); | |
$description = term_description( $term->term_id, 'tutorial_type' ); | |
$name = $term->name; | |
//create list item | |
echo '<li><div class="dashicons '.$dashicon.' tutorial-term-dashicon"></div><div class="tutorial-term"><a href="' . $link . '">' . $name . '</a>'; | |
if ( !empty( $description ) ) { | |
echo '<br /><span class="tutorial-term-description">' . strip_tags( $description, '' ).'</span>'; | |
} | |
echo '</div></li>'; | |
} //endforeach | |
echo '</ul>'; | |
} | |
?> |
<?php | |
function pods_tutorial_series_lists() { | |
if ( ! ( $parents_unique = get_transient( 'pods_tutorials_series' ) ) ) { | |
//query for all posts with parents | |
$args = array( | |
'post_type' => 'tutorial', | |
'post_parent__not_in' => array( 0 ), | |
'posts_per_page' => -1, | |
); | |
$query = new WP_Query( $args ); | |
//loop to create IDs of post parents | |
$parents = array(); | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
$post = get_post($query->post->id); | |
$parents[] = $post->post_parent; | |
} | |
//discard duplicates | |
$parents_unique = array_unique($parents); | |
set_transient( 'pods_tutorials_series', $parents_unique, WEEK_IN_SECONDS ); | |
} | |
echo '<ul id="tutorial-series-list" class="tutorials-topics-list">'; | |
//loop though parent posts | |
foreach ( $parents_unique as $series ) { | |
?> | |
<li><span class="dashicons dashicons-list-view tutorial-term-dashicon tutorial-series-dashicon"></span><a href="<?php echo get_permalink($series ); ?>"> <?php echo get_the_title($series); ?></a></li> | |
<?php | |
} | |
echo '</ul>'; | |
} |
<?php | |
//prevent new terms from being added to the tutorial_type taxonomy | |
//Thanks to http://wordpress.stackexchange.com/a/112721/25300 | |
add_action( 'pre_insert_term', 'pods_no_new_tutorial_types', 1, 2); | |
function pods_no_new_tutorial_types ($term, $taxonomy) { | |
if ('tutorial_type' === $taxonomy) { | |
return new WP_Error('term_addition_blocked', __('You cannot add terms to this taxonomy')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment