Skip to content

Commit

Permalink
ADD: tuts list shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
MjHead committed Jan 22, 2018
1 parent 17b6088 commit f0a07b5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
86 changes: 86 additions & 0 deletions includes/shortcodes/class-wapu-core-shortcode-tuts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* Row shortcode
*/

class Wapu_Core_Tuts_Shortcode extends Wapu_Core_Shortcode {

/**
* Init shortcode properties
*/
public function __construct() {

$this->tag = 'tuts-list';

$this->info = array(
'group' => array(
'name' => esc_html__( 'Content', 'wapu-core' ),
'icon' => 'welcome-add-page',
'slug' => 'wapu-content',
),
'shortcode' => array(
'name' => esc_html__( 'Tutoroals List', 'wapu-core' ),
'icon' => 'admin-links',
),
);

$this->args = array(
'class' => array(
'type' => 'text',
'title' => esc_html__( 'Custom CSS class', 'wapu-core' ),
'value' => '',
),
'id' => array(
'type' => 'text',
'title' => esc_html__( 'Custom ID', 'wapu-core' ),
'value' => '',
),
);
}

/**
* Shortcode
*
* @return void
*/
public function _shortcode( $atts, $content ) {

ob_start();

$class = ! empty( $atts['class'] ) ? esc_attr( $atts['class'] ) : false;
$id = ! empty( $atts['id'] ) ? sprintf( ' id="%s"', esc_attr( $atts['id'] ) ) : '';

$post_types = array(
'video-tutorials',
'knowledge-base',
'how-to',
'faq',
);

$args = array(
'post_type' => $post_types,
'posts_per_page' => -1,
'post_status' => 'publish',
);

$posts = get_posts( $args );

if ( ! empty( $posts ) ) {
include $this->get_template( 'content.php' );
}

return ob_get_clean();
}

/**
* Returns class instance
*
* @return [type] [description]
*/
public static function get_instance() {
return new self();
}

}

wapu_core()->init_shortcode( 'Wapu_Core_Tuts_Shortcode' );
13 changes: 13 additions & 0 deletions templates/shortcodes/tuts-list/content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="tuts-list <?php echo $class; ?>" <?php echo $id; ?>><?php
foreach ( $posts as $post ) {

$post_type = get_post_type_object( $post->post_type );

printf(
'<div class="tuts-list__item"><a href="%1$s">%2$s (%3$s)</a>',
get_permalink( $post->ID ),
$post->post_title,
$post_type->labels->name
);
}
?></div>
4 changes: 2 additions & 2 deletions wapu-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Wapuu Core
* Plugin URI: http://www.cherryframework.com/plugins/
* Description: Core for jetimpex.com.
* Version: 1.1.12
* Version: 1.2.0
* Author: JetImpex
* Author URI: http://cherryframework.com/
* Text Domain: wapu-core
Expand Down Expand Up @@ -63,7 +63,7 @@ class Wapu_Core {
*
* @var string
*/
private $version = '1.1.12';
private $version = '1.2.0';

/**
* Core page trigger
Expand Down

0 comments on commit f0a07b5

Please sign in to comment.