WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Use with custom post types

[Resolved] Use with custom post types

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author wp-maverick
    Member

    @wp-maverick

    Hey OakesDesign,
    Choosing to add automatically custom post types and pages will be a feature in next version.
    In the meanwhile, you can add your custom type name, as the type ‘page’ if you want, in the plugin PHP code. On line 105 you’ll have to adapt the following line :

    $args = array( 'post_type' => array('post'),

    with this

    $args = array( 'post_type' => array('post','page', 'XXXX'),

    Where XXXXX will be the name of yout custom type.

    This custom type must have a title, a content and a featured image of course 😉

    Let me know if this code works for you!

    Plugin Author wp-maverick
    Member

    @wp-maverick

    OK, works fine for me with this code.
    To display you own custom types, you’ll have to change the code manually.
    I’ve added a new parameter in v0.9.2 to choose between posts, pages or both (regular post types)

    I needed to create a custom version that showed the contents of a custom post type.

    I set up a new custom post type called slides

    $labels = array(
      	'name' => _x('Slides', 'slide'),
      	'singular_name' => _x('Slide', 'slide'),
      	'add_new' => _x('Add New Slide', 'slide'),
      	'add_new_item' => __('Add New publication'),
      	'edit_item' => __('Edit slide'),
      	'new_item' => __('New slide'),
      	'view_item' => __('View slide'),
      	'search_items' => __('Search slide'),
      	'not_found' =>  __('No slides found'),
      	'not_found_in_trash' => __('No slide found in Trash'),
      	'parent_item_colon' => ''
        );
        $args = array(
      	'labels' => $labels,
      	'public' => true,
      	'publicly_queryable' => true,
      	'show_ui' => true,
      	'query_var' => true,
      	'rewrite' => true,
      	'capability_type' => 'post',
      	'hierarchical' => false,
      	'menu_position' => null,
      	'supports' => array('title','editor','author','thumbnail','excerpt','comments')
    );
        register_post_type('slide',$args);

    then modified you plugin in order to select only the slide post type

    $args = array( 'post_type' => array('slide'), // not 'page'
    					   'orderby' => $prlx_sort,
    					   'order' => $prlx_order,
    					   'numberposts' =>  $prlx_slider_nb_articles,
    					   'cat' => $cat );
    
    		$myposts = get_posts( $args );
    
    		// --------------------------------------------------------
    		// HTML Output beginning

    and finally tweaked the output display in order to show the contents and thumbnail:

    /*
    	 * Generate HTML output for an article slide
    	 */
    	function get_article_slide($title, $content, $link_article, $url_image, $title_length, $alt_image = 'Alternative text')
    	{
    		// Parameters
    		if (strlen($title) > $title_length) $title = substr($title, 0, $title_length)."...";
    
    		// Slide output
    		$outputSlide  = "<div class='da-slide'>"."\n";
    		$outputSlide .= "<h2>".$title."</h2>"."\n";
    		$outputSlide .= $content."\n";
    		// $outputSlide .= "<a href='".$link_article."' class='da-link'>Read more</a>"."\n";
    		$outputSlide .= "<div class='da-img'><img src='".$url_image."' alt='".$alt_image."' /></div>"."\n";
    		$outputSlide .= "</div>"."\n";
    		return $outputSlide;
    	}
    Plugin Author wp-maverick
    Member

    @wp-maverick

    Hello jjunyent,
    great work.
    Actually, I wanted to do something new in v1.0 to simplify things about “static slides”. I’ve decided to replace this fonctionnality by adding a new custom post type. User will have the choice to display:

    • posts
    • pages
    • this new custom-post-type : parallax-slides

    I’ll certainly reuse some of you’re code 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Use with custom post types’ is closed to new replies.