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.
Related
I am using woocommerce_quantity_input pluggable function to modify the quantity input from a text box to a dropdown on my site.
On the cart page, when outputting the quantity input, I need to get the product ID so I can grab an ACF field from the single product page.
My code:
function woocommerce_quantity_input($data = null, $args = array(), $echo = true) {
global $product;
$set_quantity_limit = get_field('set_quantity_limit');
if ( !$data || is_product() ) {
$defaults = array(
'input_id' => '',
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
);
} else {
$defaults = array(
'input_id' => $data['input_id'],
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
);
}
if($set_quantity_limit){
if ( ! $product->is_sold_individually() ) {
$min = $defaults['min_value'] = 1;
$max = $defaults['max_value'] = $set_quantity_limit;
$step = $defaults['step'] = 1;
}
} else {
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else $min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else $max = 6;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else $step = 1;
}
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$selected = (($count == $defaults['input_value']) ? ' selected' : '');
$suffix_text_with_count = $count . ( ( $count == 6 ) ? ' - 1 Mastercase' : ' box - 12 ct.' );
$options .= '<option value="' . $count . '"'.$selected.'>' . ( ( $set_quantity_limit ) ? $count : $suffix_text_with_count ) . '</option>';
}
$string = '<div class="quantity quantity_select" style="' . $defaults['style'] . '">';
$string .= '<label class="screen-reader-text" for="' . esc_attr( $defaults['input_id'] ) . '">' . _x( 'Quantity', 'woocommerce' ) . '</label>';
$string .= '<select ';
$string .= 'name="' . esc_attr( $defaults['input_name'] ) . '" ';
$string .= 'title="' . _x( 'Qty', 'Product Description', 'woocommerce' ) . '" ';
$string .= 'class="qty">';
$string .= $options;
$string .= '</select>';
$string .= '</div>';
if ( $echo ) {
echo $string;
} else {
return $string;
}
}
This function applies the changes to all quantity inputs, not just those on the shop page, the single product page and the cart page.
Product is passed as as 2nd argument to the woocommerce_quantity_input function.
So use it like this:
function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
if ( is_null( $product ) ) {
$product = $GLOBALS['product'];
}
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
$product_id = $product->get_id();
echo 'Product ID = ' . $product_id;
// etc..
}
}
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 want all categories in one page with filter .I find a solution . this is working fine in my localhost but in live (Windows server) not working.
Here is this function in functions.php:
/**
* Create terms list.
*
* #since 1.5
*
* #param array $args
*
* #return string
*/
function clpr_terms_list( $args = array() ) {
$defaults = array(
'taxonomy' => 'category',
'exclude' => array(),
'menu' => true,
'count' => true,
'top_link' => true,
'class' => 'terms',
);
$options = wp_parse_args( (array) $args, $defaults );
$options = apply_filters( 'clpr_terms_list_args', $options );
$terms = get_terms( $options['taxonomy'], array( 'hide_empty' => 0, 'child_of' => 0, 'pad_counts' => 0, 'app_pad_counts' => 1 ) );
$navigation = '';
$list = '';
$groups = array();
if ( empty( $terms ) || ! is_array( $terms ) )
return html( 'p', __( 'Sorry, but no terms were found.', 'Couponize' ) );
// unset child terms
foreach ( $terms as $key => $value ) {
if ( $value->parent != 0 )
unset( $terms[ $key ] );
}
foreach ( $terms as $term ) {
$letter = mb_strtoupper( mb_substr( $term->name, 0, 1 ) );
if ( is_numeric( $letter ) )
$letter = '#';
if ( ! empty( $letter ) )
$groups[ $letter ][] = $term;
}
if ( empty( $groups ) )
return;
foreach ( $groups as $letter => $terms ) {
$old_list = $list;
$old_navigation = $navigation;
$letter_items = false;
$letter = apply_filters( 'the_title', $letter );
$letter_id = ( preg_match( '/\p{L}/', $letter ) ) ? $letter : substr( md5( $letter ), 0, 5 ); // hash special chars
$navigation .= html_link( '#' . $options['class'] . '-' . $letter_id, $letter );
$top_link = ( $options['top_link'] ) ? html_link( '#top', __( 'Top', 'Couponize' ) . ' ↑' ) : '';
$list .= '<h2 class="' . $options['class'] . '" id="' . $options['class'] . '-' . $letter_id . '">' . $letter . $top_link . '</h2>';
$list .= '<ul class="' . $options['class'] . '">';
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $options['exclude'] ) )
continue;
$letter_items = true;
$name = apply_filters( 'the_title', $term->name );
$link = html_link( get_term_link( $term, $options['taxonomy'] ), $name );
$count = ( $options['count'] ) ? ' (' . intval( $term->count ) . ')' : '';
$list .= html( 'li', $link . $count );
}
$list .= '</ul>';
if ( ! $letter_items ) {
$list = $old_list;
$navigation = $old_navigation;
}
}
$navigation = html( 'div class="grouplinks"', $navigation );
if ( $options['menu'] )
$list = $navigation . $list;
return $list;
}
/**
* Create categories list.
*
* #since 1.5
*
* #return string
*/
function clpr_categories_list() {
$args = array(
'taxonomy' => 'category',
'class' => 'categories',
);
return clpr_terms_list( $args );
}
/**
* Create stores list.
*
* #since 1.5
*
* #return string
*/
function clpr_stores_list() {
$args = array(
'taxonomy' => 'category',
'class' => 'stores',
);
return clpr_terms_list( $args );
}
I am trying to echo this function in template file.
<?php echo clpr_stores_list(); ?>
But not working. please help me.
Thanks
i have a shortcode that posts recent blog entries from a certain category on one of my web pages, however i want to display a static link at the end of everypost, is there anyway to do this?
the following code is used to display the posts:
<?php echo do_shortcode('[display-posts category="competitions" posts_per_page="4" include_excerpt="true" image_size="thumbnail" wrapper="ul"]');
Thanks in advance.
<?php
// Create the shortcode
add_shortcode( 'display-posts', 'be_display_posts_shortcode' );
function be_display_posts_shortcode( $atts ) {
// Original Attributes, for filters
$original_atts = $atts;
// Pull in shortcode attributes and set defaults
$atts = shortcode_atts( array(
'title' => '',
'author' => '',
'category' => '',
'date_format' => '(n/j/Y)',
'display_posts_off' => false,
'exclude_current' => false,
'id' => false,
'ignore_sticky_posts' => false,
'image_size' => false,
'include_title' => true,
'include_author' => false,
'include_content' => false,
'include_date' => false,
'include_excerpt' => false,
'meta_key' => '',
'meta_value' => '',
'no_posts_message' => '',
'offset' => 0,
'order' => 'DESC',
'orderby' => 'date',
'post_parent' => false,
'post_status' => 'publish',
'post_type' => 'post',
'posts_per_page' => '10',
'tag' => '',
'tax_operator' => 'IN',
'tax_term' => false,
'taxonomy' => false,
'wrapper' => 'ul',
'wrapper_class' => 'display-posts-listing',
'wrapper_id' => false,
), $atts, 'display-posts' );
// End early if shortcode should be turned off
if( $atts['display_posts_off'] )
return;
$shortcode_title = sanitize_text_field( $atts['title'] );
$author = sanitize_text_field( $atts['author'] );
$category = sanitize_text_field( $atts['category'] );
$date_format = sanitize_text_field( $atts['date_format'] );
$exclude_current = be_display_posts_bool( $atts['exclude_current'] );
$id = $atts['id']; // Sanitized later as an array of integers
$ignore_sticky_posts = be_display_posts_bool( $atts['ignore_sticky_posts'] );
$image_size = sanitize_key( $atts['image_size'] );
$include_title = be_display_posts_bool( $atts['include_title'] );
$include_author = be_display_posts_bool( $atts['include_author'] );
$include_content = be_display_posts_bool( $atts['include_content'] );
$include_date = be_display_posts_bool( $atts['include_date'] );
$include_excerpt = be_display_posts_bool( $atts['include_excerpt'] );
$meta_key = sanitize_text_field( $atts['meta_key'] );
$meta_value = sanitize_text_field( $atts['meta_value'] );
$no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
$offset = intval( $atts['offset'] );
$order = sanitize_key( $atts['order'] );
$orderby = sanitize_key( $atts['orderby'] );
$post_parent = $atts['post_parent']; // Validated later, after check for 'current'
$post_status = $atts['post_status']; // Validated later as one of a few values
$post_type = sanitize_text_field( $atts['post_type'] );
$posts_per_page = intval( $atts['posts_per_page'] );
$tag = sanitize_text_field( $atts['tag'] );
$tax_operator = $atts['tax_operator']; // Validated later as one of a few values
$tax_term = sanitize_text_field( $atts['tax_term'] );
$taxonomy = sanitize_key( $atts['taxonomy'] );
$wrapper = sanitize_text_field( $atts['wrapper'] );
$wrapper_class = sanitize_html_class( $atts['wrapper_class'] );
if( !empty( $wrapper_class ) )
$wrapper_class = ' class="' . $wrapper_class . '"';
$wrapper_id = sanitize_html_class( $atts['wrapper_id'] );
if( !empty( $wrapper_id ) )
$wrapper_id = ' id="' . $wrapper_id . '"';
// Set up initial query for post
$args = array(
'category_name' => $category,
'order' => $order,
'orderby' => $orderby,
'post_type' => explode( ',', $post_type ),
'posts_per_page' => $posts_per_page,
'tag' => $tag,
);
// Ignore Sticky Posts
if( $ignore_sticky_posts )
$args['ignore_sticky_posts'] = true;
// Meta key (for ordering)
if( !empty( $meta_key ) )
$args['meta_key'] = $meta_key;
// Meta value (for simple meta queries)
if( !empty( $meta_value ) )
$args['meta_value'] = $meta_value;
// If Post IDs
if( $id ) {
$posts_in = array_map( 'intval', explode( ',', $id ) );
$args['post__in'] = $posts_in;
}
// If Exclude Current
if( $exclude_current )
$args['post__not_in'] = array( get_the_ID() );
// Post Author
if( !empty( $author ) )
$args['author_name'] = $author;
// Offset
if( !empty( $offset ) )
$args['offset'] = $offset;
// Post Status
$post_status = explode( ', ', $post_status );
$validated = array();
$available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' );
foreach ( $post_status as $unvalidated )
if ( in_array( $unvalidated, $available ) )
$validated[] = $unvalidated;
if( !empty( $validated ) )
$args['post_status'] = $validated;
// If taxonomy attributes, create a taxonomy query
if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
// Term string to array
$tax_term = explode( ', ', $tax_term );
// Validate operator
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
$tax_operator = 'IN';
$tax_args = array(
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $tax_term,
'operator' => $tax_operator
)
)
);
// Check for multiple taxonomy queries
$count = 2;
$more_tax_queries = false;
while(
isset( $original_atts['taxonomy_' . $count] ) && !empty( $original_atts['taxonomy_' . $count] ) &&
isset( $original_atts['tax_' . $count . '_term'] ) && !empty( $original_atts['tax_' . $count . '_term'] )
):
// Sanitize values
$more_tax_queries = true;
$taxonomy = sanitize_key( $original_atts['taxonomy_' . $count] );
$terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
$tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
$tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
$tax_args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms,
'operator' => $tax_operator
);
$count++;
endwhile;
if( $more_tax_queries ):
$tax_relation = 'AND';
if( isset( $original_atts['tax_relation'] ) && in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) ) )
$tax_relation = $original_atts['tax_relation'];
$args['tax_query']['relation'] = $tax_relation;
endif;
$args = array_merge( $args, $tax_args );
}
// If post parent attribute, set up parent
if( $post_parent ) {
if( 'current' == $post_parent ) {
global $post;
$post_parent = get_the_ID();
}
$args['post_parent'] = intval( $post_parent );
}
// Set up html elements used to wrap the posts.
// Default is ul/li, but can also be ol/li and div/div
$wrapper_options = array( 'ul', 'ol', 'div' );
if( ! in_array( $wrapper, $wrapper_options ) )
$wrapper = 'ul';
$inner_wrapper = 'div' == $wrapper ? 'div' : 'li';
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $original_atts ) );
if ( ! $listing->have_posts() )
return apply_filters( 'display_posts_shortcode_no_results', wpautop( $no_posts_message ) );
$inner = '';
while ( $listing->have_posts() ): $listing->the_post(); global $post;
$image = $date = $author = $excerpt = $content = '';
if ( $include_title )
$title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . get_the_title() . '</a>';
if ( $image_size && has_post_thumbnail() )
$image = '<a class="image" href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), $image_size ) . '</a> ';
if ( $include_date )
$date = ' <span class="date">' . get_the_date( $date_format ) . '</span>';
if( $include_author )
$author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
if ( $include_excerpt )
$excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . get_the_excerpt() . '</span>';
if( $include_content ) {
add_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
$content = '<div class="content">' . apply_filters( 'the_content', get_the_content() ) . '</div>';
remove_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
}
$class = array( 'listing-item' );
$class = sanitize_html_class( apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $excerpt . $content . '</' . $inner_wrapper . '>';
// If post is set to private, only show to logged in users
if( 'private' == get_post_status( get_the_ID() ) && !current_user_can( 'read_private_posts' ) )
$output = '';
$inner .= apply_filters( 'display_posts_shortcode_output', $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class );
endwhile; wp_reset_postdata();
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<' . $wrapper . $wrapper_class . $wrapper_id . '>', $original_atts );
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>', $original_atts );
$return = $open;
if( $shortcode_title ) {
$title_tag = apply_filters( 'display_posts_shortcode_title_tag', 'h2', $original_atts );
$return .= '<' . $title_tag . ' class="display-posts-title">' . $shortcode_title . '</' . $title_tag . '>' . "\n";
}
$return .= $inner . $close;
return $return;
}
/**
* Turn off display posts shortcode
* If display full post content, any uses of [display-posts] are disabled
*
* #param array $out, returned shortcode values
* #param array $pairs, list of supported attributes and their defaults
* #param array $atts, original shortcode attributes
* #return array $out
*/
function be_display_posts_off( $out, $pairs, $atts ) {
$out['display_posts_off'] = true;
return $out;
}
/**
* Convert string to boolean
* because (bool) "false" == true
*
*/
function be_display_posts_bool( $value ) {
return !empty( $value ) && 'true' == $value ? true : false;
}
You'll want to edit you $output variable which is on line 243 on the code you've given above.
A simple amendment to add a static url will do fine, something like this:
$static_link = 'http://www.test.com/test';
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $excerpt . $content . 'Read more' . '</' . $inner_wrapper . '>';
Amend this to your requirements, say adding a proper link from the database.
Hope this helps.
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())
);