Changeset 933498
- Timestamp:
- 06/17/2014 07:19:46 AM (12 years ago)
- Location:
- add-sub-posts
- Files:
-
- 2 edited
-
inital.php (modified) (2 diffs)
-
redme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
add-sub-posts/inital.php
r854583 r933498 2 2 /** 3 3 * Plugin Name: Add sub posts 4 * Description: You can add post with sub posts under the category. 4 * Description: You can add post with sub posts under the category and latest project on widget. In single.php $args = array( 'posts_per_page' => 5, 'post_parent' => get_the_ID(), 'post_type'=>'tabs_children');$myposts = get_posts( $args ); 5 foreach ( $myposts as $post ) : setup_postdata( $post ); ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 5 6 * Author: M.Saju 6 * Version: 2.0.17 * Version: 3.0.0 7 8 */ 8 9 add_action('init', 'homeweavers_pro'); … … 214 215 215 216 register_activation_hook(__FILE__, 'tabs_activation'); 217 218 219 220 // Creating the widget 221 class subpost_widget extends WP_Widget { 222 223 function __construct() { 224 parent::__construct('subpost_widget',__('Display Latest Projects', 'subpost_widget_domain'), array( 'description' => __( 'This widget Display created projects', 'subpost_widget_domain' ), ) 225 ); 226 } 227 228 // widget form creation 229 function form($instance) { 230 231 // Check values 232 if( $instance) { 233 $title = esc_attr($instance['title']); 234 $count = esc_attr($instance['count']); 235 } else { 236 $title = __( 'Latest Projects', 'subpost_widget_domain' ); 237 $count = 0; 238 } 239 ?> 240 241 <p> 242 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'subpost_widget'); ?></label> 243 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 244 </p> 245 246 <p> 247 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('No of Projects to display:', 'subpost_widget'); ?></label> 248 <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>" /> 249 </p> 250 251 252 <?php 253 } 254 255 // update widget 256 function update($new_instance, $old_instance) { 257 $instance = $old_instance; 258 // Fields 259 $instance['title'] = strip_tags($new_instance['title']); 260 $instance['count'] = strip_tags($new_instance['count']); 261 return $instance; 262 } 263 264 // display widget 265 function widget($args, $instance) { 266 // these are the widget options 267 $title = apply_filters('widget_title', $instance['title']); 268 $count = $instance['count']; 269 270 271 $title = apply_filters( 'widget_title', $instance['title'] ); 272 // before and after widget arguments are defined by themes 273 echo $args['before_widget']; 274 if ( ! empty( $title ) ) 275 echo $args['before_title'] . $title . $args['after_title']; 276 echo '<ul>'; 277 278 project_wp_list_pages(array('title_li'=>'','depth'=>1,'post_type'=>'project','sort_column'=>'post_date','sort_order'=>'DESC'),$count); 279 echo '</ul>'; 280 // This is where you run the code and display the output 281 echo $args['after_widget']; 282 283 } 284 285 } 286 287 // Register and load the widget 288 function wpb_load_widget() { 289 register_widget( 'subpost_widget' ); 290 } 291 add_action( 'widgets_init', 'wpb_load_widget' ); 292 293 function project_wp_list_pages($args = '',$limit=10) { 294 if ( is_array($args) ) 295 $r = &$args; 296 else 297 parse_str($args, $r); 298 299 $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'), 300 'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => ''); 301 $r = array_merge($defaults, $r); 302 303 $output = ''; 304 $current_page = 0; 305 306 // sanitize, mostly to keep spaces out 307 $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']); 308 309 // Allow plugins to filter an array of excluded pages 310 $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude']))); 311 312 // Query pages. 313 $pages = get_pages($r); 314 315 $p2 = array_chunk($pages, $limit); 316 317 $pages = $p2[0]; 318 319 if ( !empty($pages) ) { 320 if ( $r['title_li'] ) 321 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 322 323 global $wp_query; 324 if ( is_page() ) 325 $current_page = $wp_query->get_queried_object_id(); 326 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); 327 328 if ( $r['title_li'] ) 329 $output .= '</ul></li>'; 330 } 331 332 $output = apply_filters('wp_list_pages', $output); 333 334 if ( $r['echo'] ) 335 echo $output; 336 else 337 return $output; 338 } 339 340 341 // page template 342 class custom_post_type_page_template { 343 344 function custom_post_type_page_template() { 345 add_action( 'init', array(&$this, 'custom_post_type_page_template_init') ); 346 add_action( 'admin_init', array(&$this, 'custom_post_type_page_template_admin_init') ); 347 add_action( 'admin_menu', array(&$this, 'custom_post_type_page_template_admin_menu') ); 348 add_action( 'save_post', array(&$this, 'custom_post_type_page_template_save_post') ); 349 add_filter( 'template_include', array(&$this, 'custom_post_type_page_template_template_include') ); 350 add_action( 'template_redirect', array(&$this, 'custom_post_type_page_template_template_redirect') ); 351 add_filter( 'body_class', array(&$this, 'custom_post_type_page_template_body_classes') ); 352 } 353 354 function custom_post_type_page_template_init() { 355 if ( function_exists('load_plugin_textdomain') ) { 356 if ( !defined('WP_PLUGIN_DIR') ) { 357 load_plugin_textdomain( 'custom-post-type-page-template', str_replace( ABSPATH, '', dirname(__FILE__) ) ); 358 } else { 359 load_plugin_textdomain( 'custom-post-type-page-template', false, dirname( plugin_basename(__FILE__) ) ); 360 } 361 } 362 } 363 364 function custom_post_type_page_template_admin_init() { 365 $options = get_option('custom_post_type_page_template'); 366 if ( !empty($options['post_types']) && is_array($options['post_types']) ) : 367 foreach( $options['post_types'] as $post_type ) : 368 add_meta_box( 'pagetemplatediv', __('Page Template', 'custom-post-type-page-template'), array(&$this, 'custom_post_type_page_template_meta_box'), $post_type, 'side', 'core'); 369 endforeach; 370 endif; 371 } 372 373 function custom_post_type_page_template_admin_menu() { 374 add_options_page( __('Custom Post Type Page Template', 'custom-post-type-page-template'), __('Custom Post Type Page Template', 'custom-post-type-page-template'), 'manage_options', basename(__FILE__), array(&$this, 'custom_post_type_page_template_options_page') ); 375 } 376 377 function custom_post_type_page_template_meta_box($post) { 378 $template = get_post_meta($post->ID, '_wp_page_template', true); 379 ?> 380 <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'custom-post-type-page-template') ?></label><select name="page_template" id="page_template"> 381 <option value='default'><?php _e('Default Template', 'custom-post-type-page-template'); ?></option> 382 <?php page_template_dropdown($template); ?> 383 </select> 384 <?php 385 } 386 387 function custom_post_type_page_template_save_post( $post_id ) { 388 if ( !empty($_POST['page_template']) ) : 389 if ( $_POST['page_template'] != 'default' ) : 390 update_post_meta($post_id, '_wp_page_template', $_POST['page_template']); 391 else : 392 delete_post_meta($post_id, '_wp_page_template'); 393 endif; 394 endif; 395 } 396 397 function custom_post_type_page_template_template_include($template) { 398 global $wp_query, $post; 399 400 if ( is_singular() && !is_page() ) : 401 $id = get_queried_object_id(); 402 $new_template = get_post_meta( $id, '_wp_page_template', true ); 403 if ( $new_template && file_exists(get_query_template( 'page', $new_template )) ) : 404 $wp_query->is_page = 1; 405 $templates[] = $new_template; 406 return get_query_template( 'page', $templates ); 407 endif; 408 endif; 409 return $template; 410 } 411 412 function custom_post_type_page_template_template_redirect() { 413 $options = get_option('custom_post_type_page_template'); 414 if ( empty($options['enforcement_mode']) ) return; 415 416 global $wp_query; 417 418 if ( is_singular() && !is_page() ) : 419 wp_cache_delete($wp_query->post->ID, 'posts'); 420 $GLOBALS['post']->post_type = 'page'; 421 wp_cache_add($wp_query->post->ID, $GLOBALS['post'], 'posts'); 422 endif; 423 } 424 425 function custom_post_type_page_template_body_classes( $classes ) { 426 if ( is_singular() && is_page_template() ) : 427 $classes[] = 'page-template'; 428 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( get_queried_object_id() ) ) ); 429 endif; 430 return $classes; 431 } 432 433 function custom_post_type_page_template_options_page() { 434 $options = get_option('custom_post_type_page_template'); 435 436 if ( !empty($_POST) ) : 437 if ( !empty($_POST['enforcement_mode']) ) $options['enforcement_mode'] = 1; 438 else unset($options['enforcement_mode']); 439 if ( empty($_POST['post_types']) ) : 440 delete_option('custom_post_type_page_template', $options); 441 unset($options['post_types']); 442 else : 443 $options['post_types'] = $_POST['post_types']; 444 update_option('custom_post_type_page_template', $options); 445 endif; 446 endif; 447 ?> 448 <div class="wrap"> 449 <div id="icon-plugins" class="icon32"><br/></div> 450 <h2><?php _e('Custom Post Type Page Template', 'custom-post-type-page-template'); ?></h2> 451 452 <?php 453 if ( !empty($_GET['settings-updated']) ) : 454 ?> 455 <div id="message" class="updated"><p><strong><?php _e( 'Settings saved.', 'custom-post-type-page-template' ); ?></strong></p></div> 456 <?php 457 endif; 458 ?> 459 460 <form action="?page=functions.php&settings-updated=true" method="post"> 461 <table class="form-table"> 462 <tbody> 463 <tr> 464 <th><label for="post_types"><?php _e('Custom Post Types', 'custom-post-type-page-template'); ?></label></th> 465 <td> 466 <?php 467 $post_types = get_post_types(array('public'=>true)); 468 foreach( $post_types as $key => $val ) : 469 if ( $key == 'attachment' || $key == 'page' ) continue; 470 ?> 471 <label><input type="checkbox" name="post_types[]" value="<?php echo $key; ?>"<?php if ( is_array($options['post_types']) && in_array($key, $options['post_types'])) echo ' checked="checked"'; ?> /> <?php echo $key; ?></label><br /> 472 <?php 473 endforeach; 474 ?> 475 </p> 476 </td> 477 </tr> 478 <tr> 479 <th><label for="enforcement_mode"><?php _e('Enforcement Mode', 'custom-post-type-page-template'); ?></label></th> 480 <td><label><input type="checkbox" name="enforcement_mode" id="enforcement_mode" value="1" <?php if ( !empty($options['enforcement_mode']) ) echo ' checked="checked"'; ?> /> <?php _e('Check this in case of using themes like Twenty Eleven, Twenty Twelve, etc.', 'custom-post-type-page-template'); ?></label></td> 481 </tr> 482 </tbody> 483 </table> 484 <p class="submit"><input type="submit" value="<?php _e('Save Changes', 'custom-post-type-page-template'); ?>" class="button-primary" id="submit" name="submit"></p> 485 </form> 486 <?php 487 } 488 } 489 global $custom_post_type_page_template; 490 $custom_post_type_page_template = new custom_post_type_page_template(); -
add-sub-posts/redme.txt
r919798 r933498 1 1 === Add Sub Posts === 2 2 Contributors: saju79shyni 3 Tags: wordpress, sql,3 Tags: child post,sub posts,post by post 4 4 Requires at least: 3.5.1 5 Tested up to: 3.8.1 6 Stable tag: 2.0.1 7 Tags: child-posts 5 Tested up to: 3.9.1 6 Stable tag: 3.5.0 8 7 9 8 Add sub post is a plugin that allows you to easily add childern posts to created Custom_post_type 'project'. … … 15 14 16 15 This plugin allows you to create a childern post after publish a parent post(post_type='project') 17 18 16 You can add post with sub posts under the category and latest project on widget. In single.php $args = array( 'posts_per_page' => 5, 'post_parent' => get_the_ID(), 'post_type'=>'tabs_children');$myposts = get_posts( $args ); 17 foreach ( $myposts as $post ) : setup_postdata( $post ); ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 19 18 20 19 == Installation == … … 28 27 29 28 == Screenshots == 30 1.Add post under category 31 2.Add sub posts under parent post 29 1.Add post under category. 30 2.Add sub posts under parent post.
Note: See TracChangeset
for help on using the changeset viewer.