#-----------------------------------------------------------------#
# Create admin recipe section
#-----------------------------------------------------------------#
function recipe_register() {
$recipe_labels = array(
'name' => __( 'Recipes', 'taxonomy general name', 'salient'),
'singular_name' => __( 'Recipe Item', 'salient'),
'search_items' => __( 'Search Recipe Items', 'salient'),
'all_items' => __( 'Recipe', 'salient'),
'parent_item' => __( 'Parent Recipe Item', 'salient'),
'edit_item' => __( 'Edit Recipe Item', 'salient'),
'update_item' => __( 'Update Recipe Item', 'salient'),
'add_new_item' => __( 'Add New Recipe Item', 'salient')
);
global $options;
$custom_slug = null;
if(!empty($options['recipe_rewrite_slug'])) $custom_slug = $options['recipe_rewrite_slug'];
$recipe_menu_icon = (floatval(get_bloginfo('version')) >= "3.8") ? 'dashicons-art' : NECTAR_FRAMEWORK_DIRECTORY . 'assets/img/icons/recipe.png';
$args = array(
'labels' => $recipe_labels,
'rewrite' => array('slug' => $custom_slug,'with_front' => false),
'singular_label' => __('Recipe', 'salient'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'hierarchical' => false,
'menu_position' => 9,
'menu_icon' => $recipe_menu_icon,
'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions')
);
register_post_type( 'recipe' , $args );
}
add_action('init', 'recipe_register');
#-----------------------------------------------------------------#
# Add taxonomys attached to recipe
#-----------------------------------------------------------------#
if (!function_exists('nectar_add_recipe_taxonomies')) {
function nectar_add_recipe_taxonomies(){
$category_labels = array(
'name' => __( 'Recipe Categories', 'salient'),
'singular_name' => __( 'Recipe Category', 'salient'),
'search_items' => __( 'Search Recipe Categories', 'salient'),
'all_items' => __( 'All Recipe Categories', 'salient'),
'parent_item' => __( 'Parent Recipe Category', 'salient'),
'edit_item' => __( 'Edit Recipe Category', 'salient'),
'update_item' => __( 'Update Recipe Category', 'salient'),
'add_new_item' => __( 'Add New Recipe Category', 'salient'),
'menu_name' => __( 'Recipe Categories', 'salient')
);
register_taxonomy("recipe-type",
array("recipe"),
array("hierarchical" => true,
'labels' => $category_labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'recipe-type' )
));
}
}
nectar_add_recipe_taxonomies();
function wpbsearchform( $form ) {
$form = '
';
return $form;
}
add_shortcode('wpbsearch', 'wpbsearchform');
// Add Shortcode
function breadcrumbs_sweeteners() {
global $post;
// Code
if(!is_home()) {
echo '';
echo 'Home > ';
$term_list = wp_get_post_terms($post->ID, get_post_taxonomies($post->ID), array("fields" => "all"));
foreach($term_list as $term_single) {
echo ''. $term_single->name . ' '; //do something here
}
//print_r($term_list);
if (is_category() || is_single()) {
the_category(' > ');
if (is_single()) {
echo ' > ';
echo '' .get_the_title().' ';
}
} elseif (is_page()) {
if ( $post->post_parent ) {
echo '';
echo get_the_title( $post->post_parent );
echo ' ';
echo ' > ';
}
echo '' .get_the_title().' ';
}
echo ' ';
}
}
add_shortcode( 'breadcrumbs', 'breadcrumbs_sweeteners' );
include("recipe-meta.php");
function most_poplar_recipes(){
global $post;
$term_list = wp_get_post_terms($post->ID, get_post_taxonomies($post->ID), array("fields" => "all"));
$blog_cat = $term_list[0]->term_id;
//print_r($term_list);
//echo $blog_cat;
echo '';
echo '
Most viewed recipes ';
echo '
';
$popularpost = new WP_Query(
array(
'posts_per_page' => 2,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'post_type' => 'recipe',
'tax_query' => array(
array(
'taxonomy' => $term_list[0]->taxonomy,
'field' => 'term_id',
'terms' => array($term_list[0]->term_id),
)
)
)
);
while ( $popularpost->have_posts() ) : $popularpost->the_post();
$recipe_type = get_post_meta($post->ID, '_nectar_recipe_recipe_type', true);
echo '';
echo '';
echo '
';
echo '
';
echo '
';
echo ' ';
endwhile;
echo ' ';
echo '
';
}
function set_views($post_ID) {
$key = 'views';
$count = get_post_meta($post_ID, $key, true); //retrieves the count
if($count == ''){ //check if the post has ever been seen
//set count to 0
$count = 0;
//just in case
delete_post_meta($post_ID, $key);
//set number of views to zero
add_post_meta($post_ID, $key, '0');
} else{ //increment number of views
$count++;
update_post_meta($post_ID, $key, $count);
}
}
//keeps the count accurate by removing prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function track_custom_post_watch ($post_ID) {
//you can use is_single here, to track all your posts. Here, we're traking custom post 'watch'
if ( !is_singular() ) return;
if ( empty ( $post_ID) ) {
//gets the global post
global $post;
//extracts the ID
$post_ID = $post->ID;
}
//calls our previously defined methos
set_views($post_ID);
}
//adds the tracker to wp_head.
add_action( 'wp_head', 'track_custom_post_watch');
function relate_recipes(){
global $post;
$term_list = wp_get_post_terms($post->ID, get_post_taxonomies($post->ID), array("fields" => "all"));
$blog_cat = $term_list[0]->term_id;
//print_r($term_list);
//echo $blog_cat;
echo '';
echo '
Related recipes ';
echo '
';
$popularpost = new WP_Query(
array(
'posts_per_page' => 2,
'post_type' => 'recipe',
'tax_query' => array(
array(
'taxonomy' => $term_list[0]->taxonomy,
'field' => 'term_id',
'terms' => array($term_list[0]->term_id),
)
)
)
);
while ( $popularpost->have_posts() ) : $popularpost->the_post();
$recipe_type = get_post_meta($post->ID, '_nectar_recipe_recipe_type', true);
echo '';
echo '';
echo '
';
echo '
';
echo '
';
echo ' ';
endwhile;
echo ' ';
echo '
';
}
class Walker_Recipe_Filter extends Walker_Category {
function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {
extract($args);
$cat_slug = esc_attr( $category->slug );
$cat_slug = apply_filters( 'list_cats', $cat_slug, $category );
$term_link = get_term_link( $category );
$class = '';
if ( !empty($current_category) ) {
$_current_category = get_term( $current_category, $category->taxonomy );
if ( $category->term_id == $current_category )
$class = 'class="current-cat"';
elseif ( $category->term_id == $_current_category->parent )
$class = 'class="current-cat-parent"';
}
$link = '';
$cat_name = esc_attr( $category->name );
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
$link .= $cat_name;
if(!empty($category->description)) {
$link .= ' '.$category->description.' ';
}
$link .= ' ';
$output .= $link;
}
}
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
//if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
//}
}
add_filter('use_block_editor_for_post', '__return_false');