[THEME: LMS] Add attribute to a shortcode
-
Hi Everyone,
I got this template that i bought named LMS | Responsive Learning Management System.
This temaplate comes with a bunch of shortcodes in it. But there is one which is the teachers shortcode, which shows up the teachers of the academy, and it works as follows:
[dt_sc_teacher columns=”2″ limit=”2″ /]
Columns limits the number of columns of which the teachers will show up, and limit, limits the amount of theacers to be shown (i think it does this depending on the date of the custom post type). So with the above code it will show 2 teachers in 2 columns.
The problem is that this is no use for me, as i want to be able to show the teachers by their own POST ID. So i would like to ask you guys if anyone can help me (I got such a limited knowladge of wordpress shortcodes but promisse i will do my best) to add an attribute to this shortcode so it allows me to do something like this:
[dt_sc_teacher columns=”2″ limit=”2″ ids=”74,80,36,45″ /]
The file where all the shortcodes are defined for my theme shows the following (i just copied in anything i think is related to the specific shortcode, please let me know if you need the full file):
/* Teachers Posts */ add_shortcode("dt_sc_teacher", array ( $this, "dt_sc_teacher" ));
function dt_sc_teacher($attrs, $content = null) { extract(shortcode_atts(array( 'columns' => '', 'limit' => '', ), $attrs)); $columns = !empty($columns) ? $columns : '4'; $limit = !empty($limit) ? $limit : '-1'; $col_class = $out = ""; switch($columns): case '1': $col_class = 'column dt-sc-one-column'; break; case '2': $col_class = 'column dt-sc-one-half'; break; case '3': $col_class = 'column dt-sc-one-third'; break; case '4': $col_class = 'column dt-sc-one-fourth'; break; case '5': $col_class = 'column dt-sc-one-fifth'; break; default: $col_class = 'column dt-sc-one-fourth'; break; endswitch; $args = array('post_type' => 'dt_teachers', 'posts_per_page' => $limit); $wp_query = new WP_Query($args); if($wp_query->have_posts()): $i = 1; while($wp_query->have_posts()): $wp_query->the_post(); $temp_class = ""; global $post; if($i == 1) $temp_class = $col_class." first"; else $temp_class = $col_class; if($i == $columns) $i = 1; else $i = $i + 1; $teacher_settings = get_post_meta ( $post->ID, '_teacher_settings', TRUE ); $s = ""; $path = plugin_dir_url ( __FILE__ ) . "images/sociables/"; if(isset($teacher_settings['teacher-social'])) { foreach ( $teacher_settings['teacher-social'] as $sociable => $social_link ) { if($social_link != '') { $img = $sociable; $class = explode(".",$img); $class = $class[0]; $s .= "<li class='{$class}'><a href='{$social_link}'> <img src='{$path}hover/{$img}' alt='{$class}'/> <img src='{$path}{$img}' alt='{$class}'/> </a>"; } } } $s = ! empty ( $s ) ? "<div class='dt-sc-social-icons'> <ul>$s</ul> </div>" : ""; //FOR AJAX... $nonce = wp_create_nonce("dt_team_member_nonce"); $link = admin_url('admin-ajax.php?ajax=true&action=dttheme_team_member&post_id='.$post->ID.'&nonce='.$nonce); $out .= '<div class="'.$temp_class.'">'; $out .= " <div class='dt-sc-team'>"; $out .= " <div class='image'>"; if(get_the_post_thumbnail($post->ID, 'full') != ''): $out .= get_the_post_thumbnail($post->ID, 'full'); else: $out .= '<img src="https://placehold.it/400x420" alt="member-image" />'; endif; $out .= " </div>"; $out .= ' <div class="team-details">'; $out .= ' <h5><a href="'.$link.'">'.get_the_title().'</a></h5>'; if($teacher_settings['role'] != '') $out .= "<h6>".$teacher_settings['role']."</h6>"; if(isset($teacher_settings['show-social-share']) && $teacher_settings['show-social-share'] != '') $out .= $s; $out .= ' </div>'; $out .= ' </div>'; $out .= '</div>'; endwhile; else: ?> <h2><?php _e('Nothing Found.', 'dt_themes'); ?></h2> <p><?php _e('Apologies, but no results were found for the requested archive.', 'dt_themes'); ?></p><?php endif; return $out; }
- The topic ‘[THEME: LMS] Add attribute to a shortcode’ is closed to new replies.