How to set first <li> link as active in a php menu - php

Hi I am working with a Wordpress gallery plugin.
I would like the first link in the filter menu to automatically be active when the page loads. This is as by default it loads ALL the images from all the categories and it's too many! Thanks.
<?php
wp_enqueue_script('imagesloaded', plugins_url('/assets/plugins/imagesloaded/imagesloaded.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_script('isotope', plugins_url('/assets/plugins/isotope/isotope.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_script('go-gallery', plugins_url('/assets/js/gallery.js', __FILE__), array('jquery', 'isotope', 'imagesloaded'), GO_GALLERY_VERSION, true);
wp_enqueue_style('go-gallery', plugins_url('/assets/css/gallery.css', __FILE__), null, GO_GALLERY_VERSION);
wp_enqueue_script('tos', plugins_url('/assets/plugins/tos/js/jquery.tosrus.min.custom.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
wp_enqueue_style('tos', plugins_url('/assets/plugins/tos/css/jquery.tosrus.custom.css', __FILE__), null, GO_GALLERY_VERSION);
$labels = array(
'name' => _x('Media Categories', 'taxonomy general name', 'go_gallery'),
'singular_name' => _x('Media Category', 'taxonomy singular name', 'go_gallery'),
'search_items' => __('Search Media Categories', 'go_gallery'),
'all_items' => __('All Media Categories', 'go_gallery'),
'parent_item' => __('Parent Media Category', 'go_gallery'),
'parent_item_colon' => __('Parent Media Category:', 'go_gallery'),
'edit_item' => __('Edit Media Category', 'go_gallery'),
'update_item' => __('Update Media Category', 'go_gallery'),
'add_new_item' => __('Add New Media Category', 'go_gallery'),
'new_item_name' => __('New Media Category Name', 'go_gallery'),
'menu_name' => __('Media Categories', 'go_gallery'),
);
$args = array(
'hierarchical' => TRUE,
'labels' => $labels,
'show_ui' => TRUE,
'show_admin_column' => TRUE,
'query_var' => TRUE,
'rewrite' => TRUE,
);
register_taxonomy('attachment_category', 'attachment', $args );
$output = '';
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => $atts['limit'],
'order' => 'DESC',
'orderby' => $atts['sort'],
'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png'
);
$categories = array();
$atts['icat'] = array_map('sanitize_title', explode(',', $atts['icat']));
foreach ( $atts['icat'] as $category ) {
if ( $term = get_term_by('slug', $category, 'attachment_category') ) {
$categories[$term->term_id] = $term;
}
}
if ( !empty($categories) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'attachment_category',
'field' => 'term_id',
'terms' => array_keys($categories)
)
);
}
$atts['menu_gap'] = min($atts['menu_gap'], 100);
$classes[] = 'go-gallery';
$classes[] = 'menu-' . $atts['menu_pos'];
$classes[] = go_gallery_bool($atts['menu_show']) ? 'menu-show' : '';
$classes[] = 'size-' . $atts['size'];
$classes[] = 'style-' . $atts['style'];
$attributes = array();
$attributes['class'] = join(' ', $classes);
$attributes['id'] = 'go-' . substr(md5(mt_rand(0, PHP_INT_MAX)), 0, 6);
$attributes['data-gap'] = intval($atts['gap']);
$attributes['data-border-color'] = $atts['border_color'];
$attributes['data-lightbox'] = go_gallery_bool($atts['lightbox']) ? 'yes' : 'no';
$attributes['data-desc-color'] = $atts['desc_color'];
$attributes['data-menu-color'] = $atts['menu_color'];
$attributes['data-menu-bg'] = $atts['menu_bg'];
$attributes['data-menu-bg-hover'] = $atts['menu_bg_hover'];
$attributes['data-menu-gap'] = $atts['menu_gap'];
$attributes['data-bg'] = $atts['bg'];
$attributes['data-border-size'] = $atts['border_size'];
$attributes['data-overlay-color'] = go_gallery_hex2rgb($atts['overlay_color']);
$thumb_size = 'medium';
if ( $atts['size'] == 'large' || ($atts['style'] == 'squared' && in_array($atts['size'], array('medium', 'large'))) ) {
$thumb_size = 'large';
}
foreach ( $attributes as $attribute => $value ) {
$attributes[$attribute] = $attribute . '="' . $value . '"';
}
$query = new WP_Query($args);
$output .= '<div ' . join(' ', $attributes) . '>';
$output .= '<ul class="go-gallery-filters">';
$output .= '<li>';
$output .= '<a data-filter="" href="#">' . __($atts['menu_button'], 'go_gallery') . '</a>';
$output .= '</li>';
foreach ( $categories as $category ) {
if ( !empty($category) ) {
$output .= '<li class="active">';
$output .= '<a data-filter="' . $category->slug . '" href="#">' . $category->name . '</a>';
$output .= '</li>';
}
}
$output .= '</ul>';
$output .= '<div class="go-gallery-list-wrapper">';
$output .= '<ul class="go-gallery-list">';
foreach ( $query->posts as $post ) {
$category_terms = wp_get_post_terms($post->ID, 'attachment_category');
$classes = array();
$classes[] = 'go-gallery-item';
foreach ( $category_terms as $category_term ) {
$classes[] = 'category-' . $category_term->slug;
}
$image_source = wp_get_attachment_image_src($post->ID, 'full');
$output .= '<li data-source="' . $image_source[0] . '" class="' . join(' ', $classes) . '">';
$output .= '<a class="image-wrap" href="' . $image_source[0] . '">';
$output .= '<figure>';
$output .= wp_get_attachment_image($post->ID, $thumb_size);
$output .= '<div class="image-overlay">';
if ( go_gallery_bool( $atts['hover_data'] ) ){
$output .= '<h3>' . $post->post_title . '</h3>';
$output .= '<h4>' . $post->post_content . '</h4>';
}
$output .= '</div>';
$output .= '</figure>';
$output .= '</a>';
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</div>';
$output .= '</div>';
return $output;
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
return 'rgba(' . join(', ', $rgb) . ', ' . $alpha .')';

That depends what you mean with "active".
:active is a CSS pseudo selector that can change the appearance of a link while it is being activated. If you want to add a css-class "active" to the first li-element in your loop, you could try something like the following:
foreach($categories as $category) {
$counter = 0; // COUNTER OF CATEGORIES...
$selected = ''; // THE STRING TO PRINT IN SELECTED LI-ELEMENT
if ( !empty($category) ) {
$selected = ($counter == 0) ? 'class="active"' : ''; // SET CLASS ACTIVE FOR THE FIRST CATEGORY
$output .= '<li '. $selected .'>';
$output .= '<a data-filter="' . $category->slug . '" href="#">' . $category->name . '</a>';
$output .= '</li>';
$counter++; //INCREMENT COUNTER OF CATEGORIES
}
}

Assuming your categories get sent via a simple link like so:
first category
second category
then you would have something like this in php:
if(isset($_GET['category']) {
$category_id = $_GET['category'];
} else {
$category_id = 1; // default
}
// this is a blank guess, we don't know where you get your data from:
$category = $categories[$category_id];
The rest depends on your data-structure.
But this is how you could set a default category.

Related

Search with um_activity (Ultimate member activity) post with post_meta and show all matching post_meta results

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');

Trying to accomplish a custom post and shortcode to connect external Database

Hello I am trying out some wordpress stuff, but once I activate a plug in with the following code, the whole server gets slow. But when I use the same API without this plug in activated it all is pretty fast.
Can you guys help me, telling me what is wrong and maybe show me how to do it better.
I try to 1. Add a custom post type and 2. for now have it possible to receive external DB information about a profile with using a shortcode.
<?php
/*
Plugin Name: Virtueel Assistent CP
Description: Custom Post plug-in voor virtuele assistenten
Author: Rico Otto - 2lemon
*/
// Our custom post type function
function create_virtueelassistent() {
register_post_type( 'virtueelassistent',
// CPT Options
array(
'labels' => array(
'name' => __( 'Virtueel Assistent' ),
'singular_name' => __( 'VirtueelAssistent' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'virtueelassistent'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_virtueelassistent' );
/*
* Creating a function to create our CPT
*/
function virtueel_assistent_cp() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'Virtueel Assistent', 'Post Type General Name' ),
'singular_name' => _x( 'Virtueel Assistent', 'Post Type Singular Name' ),
'menu_name' => __( 'Virtueel Assistenten' ),
'parent_item_colon' => __( 'Parent VA' ),
'all_items' => __( 'Alle VAs' ),
'view_item' => __( 'Bekijk VA' ),
'add_new_item' => __( 'Voeg Nieuwe VA toe' ),
'add_new' => __( 'Nieuwe VA' ),
'edit_item' => __( 'Wijzig VA' ),
'update_item' => __( 'Update VA' ),
'search_items' => __( 'Zoek VA' ),
'not_found' => __( 'Niet Gevonden' ),
'not_found_in_trash' => __( 'Niet Gevonden in Prullenbak' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'virtueelassistent' ),
'description' => __( 'Virtueel assistent profiel' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'skills' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
// Registering your Custom Post Type
register_post_type( 'virtueelassistent', $args );
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( 'init', 'virtueel_assistent_cp', 0 );
function do_getVa(){
global $wpdb;
$post = get_post();
$VaID = $post->ID;
$custom_url = '31.186.173.38:3032/profile/' . $VaID;
$curl = curl_init($custom_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$answer = curl_exec($curl);
curl_close($curl);
$res1 = json_decode($answer);
$profile_image = 'http://vabusinessacademy.2citroenen.nl/wp-content/uploads/2017/05/Liesbeth-de-Korte.jpeg';
$content = '';
$content = $content . '<div class="entry-content" vocab="http://schema.org/" typeof="Product">
<div class="et_pb_section et_pb_section_0 et_section_regular">
<div class="et_pb_row et_pb_row_0">
<div class="et_pb_column et_pb_column_4_4 et_pb_column_0 et_pb_css_mix_blend_mode_passthrough et-last-child">
<div class="et_pb_module et_pb_team_member et_pb_team_member_0 et_pb_bg_layout_light clearfix">
<div class="et_pb_team_member_image et-waypoint et_pb_animation_off">
<img property="image" src="' . $res1->profile_image . '" alt="Virtueel assistent '. $res1->name .'">
</div>
<div class="et_pb_team_member_description">
<span property="brand" style="display:none">VA Business Academy</span>
<h3 class="et_pb_module_header" property="name">' . $res1->name . '</h3>
<p property="description">' . $res1->bio . '</p>' .
'<span property="mpn" style="display: none;">' . $VaID . '</span>' .
'<div property="aggregateRating" typeof="AggregateRating" class="average-rating">
<span property="ratingValue">'. $res1->average_rating .'</span> score, gebaseerd op <span property="reviewCount">'.$res1->rating_count.'</span> reviews
<span property="bestRating" style="display:none;">' .$res1->rating_best.'</span>
<span property="worstRating" style="display:none;">' .$res1->rating_worst.'</span><div>' ;
$content = $content . '</div> <!-- .et_pb_team_member_description -->
<div class="average-rating">' . $res1->average_rating . '</div>';
if(property_exists ($res1, 'facebook_link')){$facebook_link = $res1->facebook_link;}
if(property_exists ($res1, 'twitter_link')){$twitter_link = $res1->twitter_link;}
if(property_exists ($res1, 'google_link')){$google_link = $res1->google_link;}
if(property_exists ($res1, 'linkedin_link')){$linkedin_link = $res1->linkedin_link;}
$content = $content . ' <ul class="et_pb_member_social_links">';
if(property_exists ($res1, 'facebook_link')){
$content = $content . '<li><span>Facebook</span></li>';
}
if(property_exists ($res1, 'twitter_link')){
$content = $content . '<li><span>Twitter</span></li>';
}
if(property_exists ($res1, 'google_link')){
$content = $content . '<li><span>Google+</span></li>';
}
if(property_exists ($res1, 'linkedin_link')){
$content = $content . '<li><span>LinkedIn</span></li>';
}
$content = $content . '</ul>
</div> <!-- .et_pb_team_member -->
<div class="skill-set">';
if($res1->business_mngmnt_spprt) {$content = $content . '<h4>Business Management Support</h4>';}
$content = $content . '<ul>' ;
foreach($res1->business_mngmnt_spprt as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->social_media) {$content = $content . '<h4>Social Media</h4>';}
foreach($res1->social_media as $skill)
$content = $content . '<ul>' ;
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->marketing) { $content = $content . '<h4>Marketing</h4>';}
$content = $content . '<ul>' ;
foreach($res1->marketing as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->communication) {$content = $content . '<h4>Communication</h4>';}
$content = $content . '<ul>' ;
foreach($res1->communication as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->sales) {$content = $content . '<h4>Sales</h4>';}
$content = $content . '<ul>' ;
foreach($res1->sales as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->financial) {$content = $content . '<h4>Financial</h4>';}
$content = $content . '<ul>' ;
foreach($res1->financial as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->recruitment) {$content = $content . '<h4>Recruitment</h4>';}
$content = $content . '<ul>' ;
foreach($res1->recruitment as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->human_resource_mngmnt) {$content = $content . '<h4>Human Resource Management</h4>';}
$content = $content . '<ul>' ;
foreach($res1->human_resource_mngmnt as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
if($res1->tooling) {$content = $content . '<h4>Tooling</h4>';}
$content = $content . '<ul>' ;
foreach($res1->tooling as $skill)
{
$content = $content . '<li>' . $skill . '</li>';
}
$content = $content . '</ul>';
foreach($res1->reviews as $review)
{
$content = $content . '</div>
</div>
<h2 class="review-section-title">Over VA '. $res1->name .'</h2>
<div class="et_pb_module et_pb_testimonial et_pb_testimonial_0 clearfix et_pb_bg_layout_light et_pb_text_align_left" style="background-color: #f5f5f5;" property="review" typeof="Review">
<div class="et_pb_testimonial_portrait" style="background-image: url(http://vabusinessacademy.2citroenen.nl/wp-content/uploads/2018/04/Schermafbeelding-2018-04-27-om-00.17.58.png);">
</div>
<div class="et_pb_testimonial_description">
<div class="et_pb_testimonial_description_inner">
<div property="reviewRating" typeof="Rating">
<span property="ratingValue">' .$review->rating.'<span>
<span property="bestRating" style="display:none;">' .$review->rating_best.'</span>
<span property="worstRating" style="display:none;">' .$review->rating_worst.'</span>
</div>
<meta property="datePublished" content='.$review->Created_date.'><span style="display:none;">'.$review->Created_date.'</span>
<p property="reviewBody">' . $review->text . '</p>
<span property="publisher" typeof="Organization">
<meta property="name" content='.$review->name.'>
</span>
<span style="display: none;" property="name">'. $res1->name . ' review, door: ' . $review->name.'</span>
<strong class="et_pb_testimonial_author" property="author" typeof="Person"><span property="name"' . $review->name . '</span></strong>
<p class="et_pb_testimonial_meta">CEO, ' . $review->website . '</p>
</div> <!-- .et_pb_testimonial_description_inner -->
</div> <!-- .et_pb_testimonial_description -->
</div> <!-- .et_pb_testimonial -->';
}
$content = $content . '</div> <!-- .et_pb_column -->
</div> <!-- .et_pb_row -->
</div> <!-- .et_pb_section -->
</div> <!-- .entry-content --> </div> </div>';
return $content;
}
add_shortcode('add_va_profile_page','do_getVa');
?>

Count number of posts in child custom taxonomy

i have this code:
<?php
$taxonomyName = "free";
$terms = get_terms($taxonomyName,array('parent' => 0));
foreach($terms as $term) {
$term_children = get_term_children($term->term_id,$taxonomyName);
echo '<ul>';
foreach($term_children as $term_child_id) {
$term_child = get_term_by('id',$term_child_id,$taxonomyName);
echo '<li>' . $taxtitle . ' ' . $term_child->name . '</li>';
}
echo '</ul>';
}
?>
I want to count posts from each child taxonomy of this parent taxonomy.
I want to result something like this:
echo '<li>' . $taxtitle . ' ' . $term_child->name . ' (COUNT - Episodes)</li>';
Thank you.
it should be fairly simple :
<?php
$taxonomyName = "free";
$terms = get_terms($taxonomyName,array('parent' => 0));
foreach($terms as $term) {
$term_children = get_term_children($term->term_id,$taxonomyName);
echo '<ul>';
foreach($term_children as $term_child_id) {
$term_child = get_term_by('id',$term_child_id,$taxonomyName);
$q = new WP_Query(array(
'nopaging' => true,
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $term_child_id,
'include_children' => true,
)));
$count = $q->post_count;
echo '<li>' . $taxtitle . ' ' . $term_child->name . '(Season-'.$count.')</li>';
}
echo '</ul>';
}
?>

Wordpress - How to get all Author (or all User) Names and their associated ID's?

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;
}

How do I take this existing array and add submenus?

Existing array code:
function get_menu($menu = array(), $ulclass = '', $is_main_menu = false) {
global $menu_selected;
$output = '';
if (empty($menu)) {
return $output;
}
$output .= '<ul' . (!empty($ulclass) ? (' class="' . $ulclass . '"') : '') . '>';
foreach($menu as $item) {
if (!$is_main_menu || !isset($item['hide_in_main']) || !$item['hide_in_main']) {
$li_class = (isset($item['sub']) && !empty($item['href']) ? ('dir') : '');
if (isset($menu_selected) && !empty($menu_selected) && $menu_selected == $item['href']) {
$li_class = (!empty($li_class)) ? $li_class . ' selected' : 'selected';
}
if (isset($item['li_class']) && !empty($item['li_class'])) {
$li_class .= (!empty($li_class)) ? ' ' . $item['li_class'] : $item['li_class'];
}
$output .= '<li' . (!empty($li_class) ? ' class="' . $li_class . '"': '' ) . '>';
$output .= '<a';
if (isset($item['href']) && !empty($item['href'])) {
$output .= ' href="' . $item['href'] .'"';
}
if (isset($item['title']) && !empty($item['title'])) {
$output .= ' title="' . $item['title'] .'"';
}
if (isset($item['class']) && !empty($item['class'])) {
$output .= ' class="' . $item['class'] .'"';
}
if (isset($item['target']) && !empty($item['target'])) {
$output .= ' target="' . $item['target'] .'"';
}
$output .= '>';
if (isset($item['title']) && !empty($item['title'])) {
$output .= $item['title'];
} else if (isset($item['href']) && !empty($item['href'])) {
$output .= $item['href'];
}
$output .= '</a>';
if (isset($item['sub']) && !empty($item['sub'])) {
$output .= get_menu($item['sub'], $ulclass);
}
$output .= '</li>';
}
}
$output .= '</ul>';
return $output;
}
Existing Array:
$menu[] = array(
'title' => 'Home',
'href' => 'index.php'
);
$menu[] = array(
'title' => 'Summer Activites',
'href' => 'activities.php'
);
$menu[] = array(
'title' => 'Winter Activities',
'href' => 'wactivities.php'
);
$menu[] = array(
'title' => 'Image Gallery',
'href' => 'gallery.php'
);
I want to add submenus
ie: summer activities and winter activities would be child menu items under a parent Activities
Any help would be so appreciated
Thanks in advance.
Have you actually tried doing this or are you being lazy?
Practice makes perfect!
$menu[] = array(
'title' => 'Activities',
'sub' => array(
array(
'title' => 'Summer Activites',
'href' => 'activities.php' ),
array(
'title' => 'Winter Activities',
'href' => 'wactivities.php')
)
)
);
Looks like it should work.

Categories