I have here a code that works fine except for the woocommerce product page
for example:
Home > category1 > category2 > category3
but when I go to the product page it shows only like this
Home > category1 > product
I need it to show in the product page
Home > category1 > category2 > category3 > product
I think this is where to modify the code
( if ( get_post_type() == 'product' ) {} )
Here is the code below:
function limelight_breadcrumbs()
{
global $post, $wp_query;
if ( ! $home ) $home = __( 'Home', 'limelight' );
$home_link = home_url();
$delimiter = ' » ';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
$wrap_before = ' <nav id="breadcrumbs">';
$wrap_after = '</nav> ';
if ( get_option('woocommerce_prepend_shop_page_to_urls') == "yes" && woocommerce_get_page_id( 'shop' ) && get_option( 'page_on_front' ) !== woocommerce_get_page_id( 'shop' ) )
$prepend = '' . get_the_title( woocommerce_get_page_id('shop') ) . ' ' . $delimiter;
else $prepend = '';
if ( ( ! is_front_page() && ! ( is_post_type_archive() && get_option( 'page_on_front' ) == woocommerce_get_page_id( 'shop' ) ) ) || is_paged() ) {
echo $wrap_before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $delimiter ;
if ( is_category() ) {
$cat_obj = $wp_query->get_queried_object();
$this_category = get_category( $cat_obj->term_id );
if ( $this_category->parent != 0 ) {
$parent_category = get_category( $this_category->parent );
echo get_category_parents($parent_category, TRUE, $delimiter );
}
echo $currentBefore . single_cat_title( '', false ) . $currentAfter;
} elseif ( is_home() ) {
echo $currentBefore . 'Blog' . $currentAfter;
} elseif ( is_tax('product_cat') ) {
echo $prepend;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$parents = array();
$parent = $term->parent;
while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ) );
$parent = $new_parent->parent;
}
if ( ! empty( $parents ) ) {
$parents = array_reverse( $parents );
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
echo '' . $item->name . '' . $delimiter;
}
}
$queried_object = $wp_query->get_queried_object();
echo $currentBefore . $queried_object->name . $currentAfter;
} elseif ( is_tax('product_tag') ) {
$queried_object = $wp_query->get_queried_object();
echo $prepend . $currentBefore . __('Products tagged “', 'limelight') . $queried_object->name . '”' . $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . __( 'Search results for “', 'limelight' ) . get_search_query() . '”' . $currentAfter;
} elseif ( is_day() ) {
echo '' . get_the_time('Y') . '' . $delimiter;
echo '' . get_the_time('F') . '' . $delimiter;
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '' . get_the_time('Y') . '' . $delimiter;
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_post_type_archive('product') && get_option('page_on_front') !== woocommerce_get_page_id('shop') ) {
$_name = woocommerce_get_page_id( 'shop' ) ? get_the_title( woocommerce_get_page_id( 'shop' ) ) : ucwords( get_option( 'woocommerce_shop_slug' ) );
if ( is_paged() ) {
echo $currentBefore . '' . $_name . '' . $currentAfter;
} else {
echo $currentBefore . $_name . $currentAfter;
}
} elseif ( is_single() && !is_attachment() ) { // *****************************************************************************************************************
if ( get_post_type() == 'product' ) {
echo $prepend;
if ( $terms = wp_get_object_terms( $post->ID, 'product_cat' ) ) {
$term = current( $terms );
$parents = array();
$parent = $term->parent;
while ( $parent ) {
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, 'product_cat' );
$parent = $new_parent->parent;
}
if ( ! empty( $parents ) ) {
$parents = array_reverse($parents);
foreach ( $parents as $parent ) {
$item = get_term_by( 'id', $parent, 'product_cat');
echo '' . $item->name . '' . $delimiter;
}
}
echo '' . $term->name . '' . $delimiter;
}
echo $currentBefore . get_the_title();
} elseif ( get_post_type() != 'post' ) {
$post_type = get_post_type_object( get_post_type() );
$slug = $post_type->rewrite;
echo $currentBefore . '' . $post_type->labels->singular_name . '' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;
} else {
$cat = current( get_the_category() );
echo 'BLOG' .$delimiter;
echo $currentBefore . get_the_title() . $currentAfter;
}
} elseif ( is_404() ) {
echo $currentBefore . __( 'Error 404', 'limelight' ) . $currentAfter;
} elseif ( ! is_single() && ! is_page() && get_post_type() != 'post' ) {
$post_type = get_post_type_object( get_post_type() );
if ( $post_type )
echo $currentBefore . $post_type->labels->singular_name . $currentAfter;
} elseif ( is_attachment() ) {
$parent = get_post( $post->post_parent );
$cat = get_the_category( $parent->ID );
$cat = $cat[0];
echo get_category_parents( $cat, true, '' . $delimiter );
echo $currentBefore . '' . $parent->post_title . '' . $currentAfter . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore . get_the_title() . $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = '' . get_the_title( $page->ID ) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse( $breadcrumbs );
foreach ( $breadcrumbs as $crumb )
echo $crumb . '' . $delimiter;
echo $currentBefore . get_the_title() . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . __( 'Posts tagged “', 'limelight' ) . single_tag_title('', false) . '”' . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . __( 'Author:', 'limelight' ) . ' ' . $userdata->display_name . $currentAfter;
}
if ( get_query_var( 'paged' ) )
echo ' (' . __( 'Page', 'limelight' ) . ' ' . get_query_var( 'paged' ) . ')';
echo $wrap_after;
}
}
I can't seem to do anything on this and I don't know how.
solved it by inserting pieces of code
$taxonomy = 'product_cat'; //change to your taxonomy name
// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = $delimiter;
if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
$term_ids = implode( ',' , $post_terms );
$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
$terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator );
// display post categories
echo $terms . $delimiter;
}
so this will show all the categories related to the product, hope i am right... but works fine
Related
I am using Kleo-child theme. I have an active plugin Ultimate member social activity. I want to search for any keyword from um_shared_link post_meta and see the result that keyword activity what I search for. What exactly should I do for that? Here is my code:
<?php
add_action( 'init', 'update_my_custom_type', 99 );
function update_my_custom_type() {
global $wp_post_types;
if ( post_type_exists( 'um_activity' ) ) {
// exclude from search results
$wp_post_types['um_activity']->exclude_from_search = false;
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style',
get_template_directory_uri().'/style.css' );
}
add_action( 'wp_ajax_kleo_ajax_search', 'kleo_ajax_search' );
add_action( 'wp_ajax_nopriv_kleo_ajax_search', 'kleo_ajax_search' );
if ( ! function_exists( 'kleo_ajax_search' ) ) {
function kleo_ajax_search() {
//if "s" input is missing exit
if ( empty( $_REQUEST['s'] ) && empty( $_REQUEST['bbp_search'] ) )
{
die();
}
if ( ! empty( $_REQUEST['bbp_search'] ) ) {
$search_string = $_REQUEST['bbp_search'];
} else {
$search_string = $_REQUEST['s'];
}
$output = '';
$context = 'any';
$defaults = array(
'numberposts' => 4,
'posts_per_page' => 20,
'post_type' => 'any',
'post_status' => array('publish','inherit'),
'post_password' => '',
'suppress_filters' => false,
'meta_query' => array(
array(
'key' => '_shared_link',
'value' => $_REQUEST['s'],
'compare' => 'LIKE'
)
)
);
if ( empty( $defaults['post_type'] ) ) {
$posts = null;
} else {
$defaults = apply_filters( 'kleo_ajax_query_args', $defaults );
$the_query = new WP_Query( $defaults );
$posts = $the_query->get_posts();
// echo "the query is".$the_query->request;
//die();
/*$the_query_meta = new WP_Query($defaults_meta);
$posts_meta = $the_query->get_posts();
$posts = array_merge($posts,$posts_meta);*/
}
$members = array();
$members['total'] = 0;
$groups = array();
$groups['total'] = 0;
$forums = false;
if ( function_exists( 'bp_is_active' ) && ( $context == "any" || in_array( "members", $context ) ) ) {
$members = bp_core_get_users( array(
'search_terms' => $search_string,
'per_page' => $defaults['numberposts'],
'populate_extras' => false,
) );
}
if ( function_exists( 'bp_is_active' ) && bp_is_active( "groups" ) && ( $context == "any" || in_array( "groups", $context ) ) ) {
$groups = groups_get_groups( array(
'search_terms' => $search_string,
'per_page' => $defaults['numberposts'],
'populate_extras' => false,
) );
}
if ( class_exists( 'bbPress' ) && ( $context == "any" || in_array( "forum", $context ) ) ) {
$forums = kleo_bbp_get_replies( $search_string );
}
//if there are no posts, groups nor members
if ( empty( $posts ) && $members['total'] == 0 && $groups['total'] == 0 && ! $forums ) {
$output = "<div class='kleo_ajax_entry ajax_not_found'>";
$output .= "<div class='ajax_search_content'>";
$output .= "<i class='icon icon-attention-circled'></i> ";
$output .= __( "Sorry, we haven't found anything based on your criteria.", 'kleo_framework' );
$output .= "<br>";
$output .= __( "Please try searching by different terms.", 'kleo_framework' );
$output .= "</div>";
$output .= "</div>";
echo $output;
die();
}
//if there are members
if ( $members['total'] != 0 ) {
$output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
$output .= '<h4><span>' . __( "Members", 'kleo_framework' ) . '</span></h4>';
foreach ( (array) $members['users'] as $member ) {
$image = '<img src="' . bp_core_fetch_avatar( array(
'item_id' => $member->ID,
'width' => 25,
'height' => 25,
'html' => false
) ) . '" class="kleo-rounded" alt="">';
if ( $update = bp_get_user_meta( $member->ID, 'bp_latest_update', true ) ) {
$latest_activity = char_trim( trim( strip_tags( bp_create_excerpt( $update['content'], 50, "..." ) ) ) );
} else {
$latest_activity = '';
}
$output .= "<div class ='kleo_ajax_entry'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a href='" . bp_core_get_user_domain( $member->ID ) . "' class='search_title'>";
$output .= $member->display_name;
$output .= "</a>";
$output .= "<span class='search_excerpt'>";
$output .= $latest_activity;
$output .= "</span>";
$output .= "</div>";
$output .= "</div>";
}
$output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_members_directory_permalink() . "?s=" . $search_string ) . "'>" . __( 'View member results', 'kleo_framework' ) . "</a>";
$output .= "</div>";
}
//if there are groups
if ( $groups['total'] != 0 ) {
$output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
$output .= '<h4><span>' . __( "Groups", 'kleo_framework' ) . '</span></h4>';
foreach ( (array) $groups['groups'] as $group ) {
$image = '<img src="' . bp_core_fetch_avatar( array(
'item_id' => $group->id,
'object' => 'group',
'width' => 25,
'height' => 25,
'html' => false
) ) . '" class="kleo-rounded" alt="">';
$output .= "<div class ='kleo_ajax_entry'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a href='" . bp_get_group_permalink( $group ) . "' class='search_title'>";
$output .= $group->name;
$output .= "</a>";
$output .= "</div>";
$output .= "</div>";
}
$output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_groups_directory_permalink() . "?s=" . $search_string ) . "'>" . __( 'View group results', 'kleo_framework' ) . "</a>";
$output .= "</div>";
}
//if there are posts
if ( ! empty( $posts ) ) {
$post_type_str = array();
$post_types = array();
$post_type_obj = array();
foreach ( $posts as $post ) {
$post_types[ $post->post_type ][] = $post;
if ( empty( $post_type_obj[ $post->post_type ] ) ) {
$post_type_obj[ $post->post_type ] = get_post_type_object( $post->post_type );
}
}
foreach ( $post_types as $ptype => $post_type ) {
$output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr( $post_type_obj[ $ptype ]->name ) . '">';
if ( isset( $post_type_obj[ $ptype ]->labels->name ) ) {
$output .= "<h4><span>" . $post_type_obj[ $ptype ]->labels->name . "</span></h4>";
} else {
$output .= "<hr>";
}
$count = 0;
foreach ( $post_type as $post ) {
$post_type_str[$post->post_type] = $post->post_type;
$count ++;
if ( $count > 4 ) {
continue;
}
$format = get_post_format( $post->ID );
if( $post->post_type == 'attachment') {
$img_url = wp_get_attachment_thumb_url( $post->ID );
$image = '<img src="'.aq_resize( $img_url, 44, 44, true, true, true ).'" class="kleo-rounded"/>';
} else {
if ($img_url = kleo_get_post_thumbnail_url($post->ID)) {
$image = aq_resize($img_url, 44, 44, true, true, true);
if (!$image) {
$image = $img_url;
}
$image = '<img src="' . $image . '" class="kleo-rounded">';
} else {
if ($format == 'video') {
$image = "<i class='icon icon-video'></i>";
} elseif ($format == 'image' || $format == 'gallery') {
$image = "<i class='icon icon-picture'></i>";
} else {
$image = "<i class='icon icon-link'></i>";
}
}
}
$excerpt = "";
if ( ! empty( $post->post_content ) ) {
$excerpt = $post->post_content;
$excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
$excerpt = wp_strip_all_tags($excerpt); //added to remove gogole adsense code from search excerpt
$excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
}
$link = 'activity/?wall_post='.$post->ID;
$result = $post->ID;
$classes = "format-" . $format;
$output .= "<div class ='kleo_ajax_entry $classes'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a href='$link' class='search_title'>$result";
$output .= $excerpt;
$output .= "</a>";
$output .= "<span class='search_excerpt'>";
$output .= $excerpt;
$output .= "</span>";
$output .= "</div>";
$output .= "</div>";
}
$output .= '</div>';
}
if ( ! empty( $post_type_str ) ) {
if ( count( $post_type_str ) > 1 ) {
$search_str_posts = '&post_type[]=' . implode( ',', $post_type_str );
} else {
$search_str_posts = '&post_type=' . implode( ',', $post_type_str );
}
} else {
$search_str_posts = '';
}
$output .= "<a class='ajax_view_all' href='" . esc_url( home_url( '/' ) . '?s=' . $search_string ) . $search_str_posts . "'>" . __( 'View all results', 'kleo_framework' ) . "</a>";
}
/* Forums topics search */
if ( ! empty( $forums ) ) {
$output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
$output .= '<h4><span>' . __( "Forums", 'kleo_framework' ) . '</span></h4>';
$i = 0;
foreach ( $forums as $fk => $forum ) {
$i ++;
if ( $i <= 4 ) {
$image = "<i class='icon icon-chat-1'></i>";
$output .= "<div class ='kleo_ajax_entry'>";
$output .= "<div class='ajax_search_image'>$image</div>";
$output .= "<div class='ajax_search_content'>";
$output .= "<a href='" . $forum['url'] . "' class='search_title'>";
$output .= $forum['name'];
$output .= "</a>";
//$output .= "<span class='search_excerpt'>";
//$output .= $latest_activity;
//$output .= "</span>";
$output .= "</div>";
$output .= "</div>";
}
}
$output .= "<a class='ajax_view_all' href='" . esc_url( bbp_get_search_url() . "?bbp_search=" . $search_string ) . "'>" . __( 'View forum results', 'kleo_framework' ) . "</a>";
$output .= "</div>";
}
echo $output;
die();
}
}
function searchfilter($query) {
if ($query->is_search) {
$query->set('post_type',array('um_activity'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
I have total 600 product in my website and 200 product have these type of title 'mickey' clock. When I searching product with 'mickey' clo or when search product with mikey' clo I getting search result. But when I searching mickey clo it doesn't find any products. Can you please help me to solve my problem. Following my query I using search function.
if ( ! class_exists( 'Amely_Ajax_Search' ) ) {
class Amely_Ajax_Search {
public function __construct() {
if ( class_exists( 'WpbakeryShortcodeParams' ) ) {
WpbakeryShortcodeParams::addField( 'ajax-search', array( $this, 'render' ) );
}
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
// VC ajax search
add_action( 'wp_ajax_vc_ajax_search', array( $this, 'ajax_search' ) );
add_action( 'wp_ajax_nopriv_vc_ajax_search', array( $this, 'ajax_search' ) );
add_filter( 'posts_where', array( $this, 'title_like_posts_where' ), 10, 2 );
}
function ajax_search() {
$q = isset( $_GET['q'] ) ? $_GET['q'] : '';
$type = urldecode( isset( $_GET['type'] ) ? $_GET['type'] : 'post_type' );
$get = urldecode( isset( $_GET['get'] ) ? $_GET['get'] : 'post' );
$field = urldecode( isset( $_GET['field'] ) ? $_GET['field'] : 'id' );
$values = explode( ',', $get );
$post_arr = array();
if ( $type == 'post_type' ) {
$params = array(
'post_title_like' => $q,
'posts_per_page' => 10,
'post_type' => $values,
'ignore_sticky_posts' => 1,
);
$loop = new WP_Query( $params );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) {
$loop->the_post();
$post_arr[] = array(
'id' => get_the_ID(),
'name' => get_the_title(),
);
}
}
wp_reset_postdata();
} elseif ( $type == 'taxonomy' ) {
global $wpdb;
$cat_id = (int) $q;
$q = trim( $q );
$post_meta_infos = $wpdb->get_results( $wpdb->prepare( "SELECT a.term_id AS id, b.name as name, b.slug AS slug
FROM {$wpdb->term_taxonomy} AS a
INNER JOIN {$wpdb->terms} AS b ON b.term_id = a.term_id
WHERE a.taxonomy = '{$get}' AND (a.term_id = '%d' OR b.slug LIKE '%%%s%%' OR b.name LIKE '%%%s%%' )", $cat_id > 0 ? $cat_id : - 1, stripslashes( $q ), stripslashes( $q ) ), ARRAY_A );
$result = array();
if ( is_array( $post_meta_infos ) && ! empty( $post_meta_infos ) ) {
foreach ( $post_meta_infos as $value ) {
$data = array();
$data['id'] = ( $field == 'slug' ) ? $value['slug'] : $value['id'];
$data['name'] = esc_html__( 'Id', 'amely' ) . ': ' . $value['id'] . ( ( strlen( $value['name'] ) > 0 ) ? ' - ' . esc_html__( 'Name', 'amely' ) . ': ' . $value['name'] : '' ) . ( ( strlen( $value['slug'] ) > 0 ) ? ' - ' . esc_html__( 'Slug', 'amely' ) . ': ' . $value['slug'] : '' );
$result[] = $data;
}
}
}
wp_send_json( $result );
}
public function title_like_posts_where( $where, $wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
}
public function admin_scripts() {
wp_enqueue_style( 'amely-ajax-search', AMELY_THEME_URI . '/includes/vc-extend/vc-params/amely-ajax-search/token-input.css' );
wp_enqueue_script( 'amely-ajax-search', AMELY_THEME_URI . '/includes/vc-extend/vc-params/amely-ajax-search/jquery.tokeninput.min.js', array( 'jquery' ), AMELY_THEME_VERSION, true );
}
public function render( $settings, $value ) {
$param_name = isset( $settings['param_name'] ) ? $settings['param_name'] : '';
$options = isset( $settings['options'] ) ? $settings['options'] : array();
$type = isset( $options['type'] ) ? $options['type'] : 'post_type';
$get = isset( $options['get'] ) ? $options['get'] : 'post';
$field = isset( $options['field'] ) ? $options['field'] : 'id';
$ajax_limit = isset( $options['ajax_limit'] ) ? $options['ajax_limit'] : 10;
$id = uniqid( 'tokeninput-' );
$pre_populate = '';
if ( $value != '' ) {
$value_items = explode( ',', $value );
if ( $type == 'post_type' ) {
foreach ( $value_items as $value_item ) {
$value_item_info = get_post( trim( $value_item ) );
$pre_populate .= '{id: ' . $value_item_info->ID . ', name: "' . $value_item_info->post_title . '"},';
}
} elseif ( $type == 'taxonomy' ) {
foreach ( $value_items as $value_item ) {
$value_item_info = get_term_by( $field, trim( $value_item ), $get );
$pre_populate .= '{id: "' . trim( $value_item ) . '", name: "ID: ' . $value_item->term_id . ( ( strlen( $value_item_info->name ) > 0 ) ? ' - ' . esc_html__( 'Name', 'amely' ) . ': ' . $value_item_info->name : '' ) . ( strlen( $value_item_info->slug ) > 0 ? ' - ' . esc_html__( 'Slug', 'amely' ) . ': ' . $value_item_info->slug : '' ) . '"},';
}
}
}
$output = '<div class="tokeninput">';
$output .= '<input id="' . $id . '" name="' . $param_name . '" value="' . $value . '" type="text" class="wpb_vc_param_value" />';
$output .= '</div>';
$output .= '<script>jQuery("#' . $id . '").tokenInput("' . esc_js( admin_url( 'admin-ajax.php' ) ) . '?action=vc_ajax_search&type=' . urlencode( $type ) . '&get=' . urlencode( $get ) . '&field=' . urlencode( $field ) . '", {
prePopulate: [' . $pre_populate . '], resultsLimit: ' . $ajax_limit . ', excludeCurrent: true } );</script>';
return $output;
}
}
new Amely_Ajax_Search();
}
I currently have the 'Our Team' plugin installed to display team members.
At the moment, the staff description (that appears in the WISYWIG editor area), is pulled through onto the team page along with all the other staff details.
As there is quite a bit of text for each, i would like to have it so that there is just a 'Read about me' link, and the description text appears in a lightbox instead.
I already have a Lightbox plugin in use on the website (WP Lightbox 2), but just need to know how i can change the 'Our Team' template file so that it displays the link rather than the whole block of text.
Below is the 'woothemes-our-team-template.php' file:
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! function_exists( 'woothemes_get_our_team' ) ) {
/**
* Wrapper function to get the team members from the Woothemes_Our_Team class.
* #param string/array $args Arguments.
* #since 1.0.0
* #return array/boolean Array if true, boolean if false.
*/
function woothemes_get_our_team ( $args = '' ) {
global $woothemes_our_team;
return $woothemes_our_team->get_our_team( $args );
} // End woothemes_get_our_team()
}
/**
* Enable the usage of do_action( 'woothemes_our_team' ) to display team members within a theme/plugin.
*
* #since 1.0.0
*/
add_action( 'woothemes_our_team', 'woothemes_our_team' );
if ( ! function_exists( 'woothemes_our_team' ) ) {
/**
* Display or return HTML-formatted team members.
* #param string/array $args Arguments.
* #since 1.0.0
* #return string
*/
function woothemes_our_team ( $args = '' ) {
global $post, $more;
$defaults = apply_filters( 'woothemes_our_team_default_args', array(
'limit' => 12,
'per_row' => null,
'orderby' => 'menu_order',
'order' => 'DESC',
'id' => 0,
'slug' => null,
'display_author' => true,
'display_additional' => true,
'display_avatar' => true,
'display_url' => true,
'display_twitter' => true,
'display_author_archive' => true,
'display_role' => true,
'contact_email' => true,
'tel' => true,
'effect' => 'fade', // Options: 'fade', 'none'
'pagination' => false,
'echo' => true,
'size' => 250,
'title' => '',
'before' => '<div class="widget widget_woothemes_our_team">',
'after' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
'category' => 0
) );
$args = wp_parse_args( $args, $defaults );
// Allow child themes/plugins to filter here.
$args = apply_filters( 'woothemes_our_team_args', $args );
$html = '';
do_action( 'woothemes_our_team_before', $args );
// The Query.
$query = woothemes_get_our_team( $args );
// The Display.
if ( ! is_wp_error( $query ) && is_array( $query ) && count( $query ) > 0 ) {
$class = '';
if ( is_numeric( $args['per_row'] ) ) {
$class .= ' columns-' . intval( $args['per_row'] );
}
if ( 'none' != $args['effect'] ) {
$class .= ' effect-' . $args['effect'];
}
$html .= $args['before'] . "\n";
if ( '' != $args['title'] ) {
$html .= html_entity_decode( $args['before_title'] ) . esc_html( $args['title'] ) . html_entity_decode( $args['after_title'] ) . "\n"; }
$html .= '<div class="team-members component' . esc_attr( $class ) . '">' . "\n";
// Begin templating logic.
$tpl = '<div itemscope itemtype="http://schema.org/Person" class="%%CLASS%%">%%AVATAR%% %%TITLE%% <div id="team-member-%%ID%%" class="team-member-text" itemprop="description">%%TEXT%% %%AUTHOR%%</div></div>';
$tpl = apply_filters( 'woothemes_our_team_item_template', $tpl, $args );
$count = 0;
foreach ( $query as $post ) {
$count++;
$template = $tpl;
$css_class = apply_filters( 'woothemes_our_team_member_class', $css_class = 'team-member' );
if ( ( is_numeric( $args['per_row'] ) && ( 0 == ( $count - 1 ) % $args['per_row'] ) ) || 1 == $count ) { $css_class .= ' first'; }
if ( ( is_numeric( $args['per_row'] ) && ( 0 == $count % $args['per_row'] ) ) ) { $css_class .= ' last'; }
// Add a CSS class if no image is available.
if ( isset( $post->image ) && ( '' == $post->image ) ) {
$css_class .= ' no-image';
}
setup_postdata( $post );
$title = '';
$title_name = '';
// If we need to display the title, get the data
if ( ( get_the_title( $post ) != '' ) && true == $args['display_author'] ) {
$title .= '<h3 itemprop="name" class="member">';
if ( true == $args['display_url'] && '' != $post->url && apply_filters( 'woothemes_our_team_member_url', true ) ) {
$title .= '<a href="' . esc_url( $post->url ) . '">' . "\n";
}
$title_name = get_the_title( $post );
$title .= $title_name;
if ( true == $args['display_url'] && '' != $post->url && apply_filters( 'woothemes_our_team_member_url', true ) ) {
$title .= '</a>' . "\n";
}
$title .= '</h3><!--/.member-->' . "\n";
$member_role = '';
if ( true == $args['display_role'] && isset( $post->byline ) && '' != $post->byline && apply_filters( 'woothemes_our_team_member_role', true ) ) {
$member_role .= ' <p class="role" itemprop="jobTitle">' . $post->byline . '</p><!--/.excerpt-->' . "\n";
}
$title .= apply_filters( 'woothemes_our_team_member_fields_display', $member_role );
}
// Templating engine replacement.
$template = str_replace( '%%TITLE%%', $title, $template );
$author = '';
$author_text = '';
$user = $post->user_id;
// If we need to display the author, get the data.
if ( true == $args['display_additional'] ) {
$author .= '<ul class="author-details">';
$member_fields = '';
if ( true == $args['display_author_archive'] && apply_filters( 'woothemes_our_team_member_user_id', true ) ) {
// User didn't select an item from the autocomplete list
// Let's try to get the user from the search query
if ( 0 == $post->user_id && '' != $post->user_search ) {
$user = get_user_by( 'slug', $post->user_search );
if ( $user ) {
$user = $user->ID;
}
}
if ( 0 != $user ) {
$member_fields .= '<li class="our-team-author-archive" itemprop="url">' . sprintf( __( 'Read posts by %1$s', 'our-team-by-woothemes' ), get_the_title() ) . '</li>' . "\n";
}
}
if ( true == $args['contact_email'] && '' != $post->contact_email && apply_filters( 'woothemes_our_team_member_contact_email', true ) ) {
$member_fields .= '<li class="our-team-contact-email" itemprop="email">' . __( 'Email me ', 'our-team-by-woothemes' ) . '</li>';
}
if ( true == $args['tel'] && '' != $post->tel && apply_filters( 'woothemes_our_team_member_tel', true ) ) {
$call_protocol = apply_filters( 'woothemes_our_team_call_protocol', $protocol = 'tel' );
$member_fields .= '<li class="our-team-tel" itemprop="telephone"><span>' . __( 'Tel: ', 'our-team-by-woothemes' ) . '</span>' . esc_html( $post->tel ) . '</li>';
}
if ( true == $args['display_twitter'] && '' != $post->twitter && apply_filters( 'woothemes_our_team_member_twitter', true ) ) {
$member_fields .= '<li class="our-team-twitter" itemprop="contactPoint">Follow #' . esc_html( $post->twitter ) . '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document, "script", "twitter-wjs");</script></li>' . "\n";
}
$author .= apply_filters( 'woothemes_our_member_fields_display', $member_fields );
$author .= '</ul>';
// Templating engine replacement.
$template = str_replace( '%%AUTHOR%%', $author, $template );
} else {
$template = str_replace( '%%AUTHOR%%', '', $template );
}
// Templating logic replacement.
$template = str_replace( '%%ID%%', get_the_ID(), $template );
$template = str_replace( '%%CLASS%%', esc_attr( $css_class ), $template );
if ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] ) {
$template = str_replace( '%%AVATAR%%', '<figure itemprop="image">' . $post->image . '</figure>', $template );
} else {
$template = str_replace( '%%AVATAR%%', '', $template );
}
// Remove any remaining %%AVATAR%% template tags.
$template = str_replace( '%%AVATAR%%', '', $template );
$real_more = $more;
$more = 0;
$content = apply_filters( 'woothemes_our_team_content', wpautop( get_the_content( __( 'Read full biography...', 'our-team-by-woothemes' ) ) ), $post );
$more = $real_more;
// Display bio if Team Member is mapped to a user on this site.
if ( apply_filters( 'woothemes_our_team_display_bio', true ) && 0 != $user ) {
if ( '' != get_the_author_meta( 'description', $user ) ) {
$content = wpautop( get_the_author_meta( 'description', $user ) );
}
}
$template = str_replace( '%%TEXT%%', $content, $template );
// filter the individual team member html
$template = apply_filters( 'woothemes_our_team_member_html', $template, $post );
// Assign for output.
$html .= $template;
}
wp_reset_postdata();
if ( $args['pagination'] == true && count( $query ) > 1 && $args['effect'] != 'none' ) {
$html .= '<div class="pagination">' . "\n";
$html .= '' . apply_filters( 'woothemes_our_team_prev_btn', '← ' . __( 'Previous', 'our-team-by-woothemes' ) ) . '' . "\n";
$html .= '' . apply_filters( 'woothemes_our_team_next_btn', __( 'Next', 'our-team-by-woothemes' ) . ' →' ) . '' . "\n";
$html .= '</div><!--/.pagination-->' . "\n";
}
$html .= '</div><!--/.team-members-->' . "\n";
$html .= $args['after'] . "\n";
}
// Allow child themes/plugins to filter here.
$html = apply_filters( 'woothemes_our_team_html', $html, $query, $args );
if ( $args['echo'] != true ) {
return $html;
}
// Should only run is "echo" is set to true.
echo $html;
do_action( 'woothemes_our_team_after', $args ); // Only if "echo" is set to true.
} // End woothemes_our_team()
}
if ( ! function_exists( 'woothemes_our_team_shortcode' ) ) {
/**
* The shortcode function.
* #since 1.0.0
* #param array $atts Shortcode attributes.
* #param string $content If the shortcode is a wrapper, this is the content being wrapped.
* #return string Output using the template tag.
*/
function woothemes_our_team_shortcode ( $atts, $content = null ) {
$args = (array)$atts;
$defaults = array(
'limit' => 12,
'per_row' => null,
'orderby' => 'menu_order',
'order' => 'DESC',
'id' => 0,
'slug' => null,
'display_author' => true,
'display_additional' => true,
'display_avatar' => true,
'display_url' => true,
'display_author_archive' => true,
'display_twitter' => true,
'display_role' => true,
'effect' => 'fade', // Options: 'fade', 'none'
'pagination' => false,
'echo' => true,
'size' => 250,
'category' => 0,
'title' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
);
$args = shortcode_atts( $defaults, $atts );
// Make sure we return and don't echo.
$args['echo'] = false;
// Fix integers.
if ( isset( $args['limit'] ) ) {
$args['limit'] = intval( $args['limit'] );
}
if ( isset( $args['size'] ) && ( 0 < intval( $args['size'] ) ) ) {
$args['size'] = intval( $args['size'] );
}
if ( isset( $args['category'] ) && is_numeric( $args['category'] ) ) {
$args['category'] = intval( $args['category'] );
}
// Fix booleans.
foreach ( array( 'display_author', 'display_additional', 'display_url', 'display_author_archive', 'display_twitter', 'display_role', 'pagination', 'display_avatar' ) as $k => $v ) {
if ( isset( $args[$v] ) && ( 'true' == $args[$v] ) ) {
$args[$v] = true;
} else {
$args[$v] = false;
}
}
return woothemes_our_team( $args );
} // End woothemes_our_team_shortcode()
}
add_shortcode( 'woothemes_our_team', 'woothemes_our_team_shortcode' );
if ( ! function_exists( 'woothemes_our_team_content_default_filters' ) ) {
/**
* Adds default filters to the "woothemes_our_team_content" filter point.
* #since 1.0.0
* #return void
*/
function woothemes_our_team_content_default_filters () {
add_filter( 'woothemes_our_team_content', 'do_shortcode' );
} // End woothemes_our_team_content_default_filters()
add_action( 'woothemes_our_team_before', 'woothemes_our_team_content_default_filters' );
}
add_filter( 'the_content', 'woothemes_our_team_content' );
/**
* Display team member data on single / archive pages
* #since 1.4.0
* #return $content the post content
*/
function woothemes_our_team_content( $content ) {
global $post;
$team_member_email = esc_attr( get_post_meta( $post->ID, '_gravatar_email', true ) );
$user = esc_attr( get_post_meta( $post->ID, '_user_id', true ) );
$user_search = esc_attr( get_post_meta( $post->ID, '_user_search', true ) );
$twitter = esc_attr( get_post_meta( $post->ID, '_twitter', true ) );
$role = esc_attr( get_post_meta( $post->ID, '_byline', true ) );
$url = esc_attr( get_post_meta( $post->ID, '_url', true ) );
$tel = esc_attr( get_post_meta( $post->ID, '_tel', true ) );
$contact_email = esc_attr( get_post_meta( $post->ID, '_contact_email', true ) );
if ( 'team-member' == get_post_type() ) {
$team_member_gravatar = '';
$team_member_role = '';
$member_fields = '';
$author = '';
if ( isset( $team_member_email ) && ( '' != $team_member_email ) ) {
$team_member_gravatar = '<figure itemprop="image">' . get_avatar( $team_member_email, 250 ) . '</figure>';
}
if ( isset( $role ) && '' != $role && apply_filters( 'woothemes_our_team_member_role', true ) ) {
$team_member_role .= ' <p class="role" itemprop="jobTitle">' . $role . '</p>' . "\n";
}
$author .= '<ul class="author-details">';
if ( apply_filters( 'woothemes_our_team_member_user_id', true ) ) {
if ( 0 == $user && '' != $user_search ) {
$user = get_user_by( 'slug', $user_search );
if ( $user ) {
$user = $user;
}
}
if ( 0 != $user ) {
$member_fields .= '<li class="our-team-author-archive" itemprop="url">' . sprintf( __( 'Read posts by %1$s', 'woothemes' ), get_the_title() ) . '</li>' . "\n";
}
}
if ( '' != $tel && apply_filters( 'woothemes_our_team_member_contact_email', true ) ) {
$member_fields .= '<li class="our-team-contact-email" itemprop="email">' . __( 'Email ', 'our-team-by-woothemes' ) . get_the_title() . '</li>';
}
if ( '' != $tel && apply_filters( 'woothemes_our_team_member_tel', true ) ) {
$call_protocol = apply_filters( 'woothemes_our_team_call_protocol', $protocol = 'tel' );
$member_fields .= '<li class="our-team-tel" itemprop="telephone"><span>' . __( 'Tel: ', 'our-team-by-woothemes' ) . '</span>' . $tel . '</li>';
}
if ( '' != $twitter && apply_filters( 'woothemes_our_team_member_twitter', true ) ) {
$member_fields .= '<li class="our-team-twitter" itemprop="contactPoint">Follow #' . esc_html( $twitter ) . '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document, "script", "twitter-wjs");</script></li>' . "\n";
}
$author .= apply_filters( 'woothemes_our_member_fields_display', $member_fields );
$author .= '</ul>';
return $team_member_gravatar . $team_member_role . $content . $author;
} else {
return $content;
}
}
You can filter the template:
function so_27863277_our_team_template( $tpl, $args ){
$tpl = '<div itemscope itemtype="http://schema.org/Person" class="%%CLASS%%">%%AVATAR%% %%TITLE%% Read About Me<div id="team-member-%%ID%%" class="team-member-text" itemprop="description">%%TEXT%% %%AUTHOR%%</div></div>';
return $tpl;
}
add_filter( 'woothemes_our_team_item_template', 'so_27863277_our_team_template', 10, 2 );
Then by default, you might also want to style the team-member-text div so that it is hidden.
.team-member-text{ display: none; }
I'm not sure how to make it work with your particular lightbox plugin so you will have to adapt that part yourself.
I am trying to customise the following code so it displays all sibling pages of the current page, but instead of outputting them as the title, they are output as bulletpoints (styled bulletpoints so an image, 'images/bulletpoint.gif'). I have the following code that displays them as the names, but can't seem to customise them to display as an image. Any ideas?
Many thanks
<ul class="subnav_right">
<?php
global $post;
$current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID );
wp_list_pages( array(
'title_li' => '',
'child_of' => $current_page_parent,
'depth' => '1' )
);
?>
</ul>
You can customize using walker.I have done it using walker. check following code:
Walker Class:
class Custom_Walker extends Walker_Page {
function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
if ( $depth )
$indent = str_repeat("\t", $depth);
else
$indent = '';
extract($args, EXTR_SKIP);
$css_class = array('page_item', 'page-item-'.$page->ID);
if ( !empty($current_page) ) {
$_current_page = get_post( $current_page );
if ( in_array( $page->ID, $_current_page->ancestors ) )
$css_class[] = 'current_page_ancestor';
if ( $page->ID == $current_page )
$css_class[] = 'current_page_item';
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
$css_class[] = 'current_page_parent';
}
elseif ( $page->ID == get_option('page_for_posts') ) {
$css_class[] = 'current_page_parent';
}
$css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
$icon_class = get_post_meta($page->ID, 'icon_class', true); //Retrieve stored icon class from post meta
$output .= $indent . '<li class="' . $css_class . '">';
$output .= '<a href="' . get_permalink($page->ID) . '">' . $link_before;
if($icon_class){ //Test if $icon_class exists
$output .= '<span class="' . $icon_class . '"></span>'; //If it exists output a span with the $icon_class attached to it
}
if($depth!=0){
$output .= apply_filters( 'the_title', '', $page->ID );
}else {
$output .= apply_filters( 'the_title', $page->post_title, $page->ID );
}
$output .= $link_after . '</a>';
if ( !empty($show_date) ) {
if ( 'modified' == $show_date )
$time = $page->post_modified;
else
$time = $page->post_date;
$output .= " " . mysql2date($date_format, $time);
}
}
}
Pass walker in argumnent like:
wp_list_pages( array( 'title_li' => '',
'child_of' => $current_page_parent,
'depth' => '1',
'walker' => new Custom_Walker())
);
At the moment I am doing the following to get a list of all authors:
$authors = wp_list_authors('html=0&style=none&echo=0&exclude_admin=1&optioncount=0&show_fullname=1&hide_empty=1&orderby=name&order=ASC');
$authors_array = explode(',', $authors);
for ($j = 0; $j < count($authors_array); $j++)
{
echo '<li id="">'.$authors_array[$j].'</li>';
}
How can I also get the user's id?
I have looked everywhere and I can't think of a way to get all authors and another bit of meta data.
Another way I found was to do the following (swear I couldn't find anything like this earlier):
$authors = get_users('role=author&orderby=display_name&order=ASC');
foreach ($authors as $author) {
if (count_user_posts($author->ID) > 0) {
echo '<li id="' . $author->ID . '">' . $author->display_name . '</li>';
}
}
You can either override the function in functions.php or create a new function based on the original. Looking at the code it's easy enough to just include the $author_id in the foreach loop.
Code for original is here
Try this and make sure you add the new parameter (includeauthorid) into the function call...
$authors = wp_list_authors('html=0&style=none&echo=0&exclude_admin=1&optioncount=0&show_fullname=1&hide_empty=1&orderby=name&order=ASC&includeauthorid=1');
new function - ps I wouldn't recommend changing the original. Just put this in functions.php.
function wp_list_authors($args = '') {
global $wpdb;
$defaults = array(
'orderby' => 'name', 'order' => 'ASC', 'number' => '',
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
'style' => 'list', 'html' => true,
'includeauthorid' => false
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
$return = '';
$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
$query_args['fields'] = 'ids';
$authors = get_users( $query_args );
$author_count = array();
foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
$author_count[$row->post_author] = $row->count;
foreach ( $authors as $author_id ) {
$author = get_userdata( $author_id );
if ( $exclude_admin && 'admin' == $author->display_name )
continue;
$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
if ( !$posts && $hide_empty )
continue;
$link = '';
if ( $show_fullname && $author->first_name && $author->last_name )
$name = "$author->first_name $author->last_name";
else
$name = $author->display_name;
if( $includeauthorid)
$name .= ' ('. $author_id .')';
if ( !$html ) {
$return .= $name . ', ';
continue; // No need to go further to process HTML.
}
if ( 'list' == $style ) {
$return .= '<li>';
}
$link = '' . $name . '';
if ( !empty( $feed_image ) || !empty( $feed ) ) {
$link .= ' ';
if ( empty( $feed_image ) ) {
$link .= '(';
}
$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
$alt = $title = '';
if ( !empty( $feed ) ) {
$title = ' title="' . esc_attr( $feed ) . '"';
$alt = ' alt="' . esc_attr( $feed ) . '"';
$name = $feed;
$link .= $title;
}
$link .= '>';
if ( !empty( $feed_image ) )
$link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';
else
$link .= $name;
$link .= '</a>';
if ( empty( $feed_image ) )
$link .= ')';
}
if ( $optioncount )
$link .= ' ('. $posts . ')';
$return .= $link;
$return .= ( 'list' == $style ) ? '</li>' : ', ';
}
$return = rtrim($return, ', ');
if ( !$echo )
return $return;
echo $return;
}