Plugin Directory

Changeset 2270322


Ignore:
Timestamp:
03/29/2020 06:25:00 PM (6 years ago)
Author:
sdavis2702
Message:

Add setting to order posts ascending or descending

Location:
simple-course-creator/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • simple-course-creator/trunk/assets/css/admin-style.css

    r893716 r2270322  
    44}
    55.wp-people-group {
    6     margin-top: 0;
     6    margin-top: 4px;
    77}
    88.wp-person {
  • simple-course-creator/trunk/includes/admin/class-scc-settings-page.php

    r1443528 r2270322  
    5454
    5555        // add option for ordering posts
    56         add_settings_field( 'scc_orderby', __( 'Order Posts By', 'scc'), array( $this, 'course_orderby' ), 'simple_course_creator', 'course_display_settings' );
     56        add_settings_field( 'scc_orderby', __( 'Sort Posts By', 'scc'), array( $this, 'course_orderby' ), 'simple_course_creator', 'course_display_settings' );
     57
     58        // add option for ordering posts ASC or DESC
     59        add_settings_field( 'scc_order', __( 'Order Posts', 'scc'), array( $this, 'course_order' ), 'simple_course_creator', 'course_display_settings' );
    5760
    5861        // add option for choosing current post text/font properties
     
    8689        $options = wp_parse_args( $options, $default );
    8790
    88         // possible course position options
     91        // possible list options
    8992        $course_container = array(
    9093            'above' => array( 'value' => 'above', 'desc' => __( 'Above Content', 'scc' ) ),
     
    116119        $options = wp_parse_args( $options, $default );
    117120
    118         // possible list style options
     121        // possible list options
    119122        $list_type = array(
    120123            'ordered'   => array( 'value' => 'ordered', 'desc' => __( 'Numbered List', 'scc' ) ),
     
    145148        $options = wp_parse_args( $options, $default );
    146149
    147         // possible list style options
     150        // possible list options
    148151        $orderby = array(
    149152            'date'          => array( 'value' => 'date', 'desc' => __( 'Date', 'scc' ) ),
     
    160163            <?php } ?>
    161164        </select>
    162         <label><?php _e( 'Choose how to order to order your post listing.', 'scc' ); ?></label>
     165        <label><?php _e( 'Choose a parameter for ordering your post listing.', 'scc' ); ?></label>
     166        <?php
     167    }
     168
     169
     170    /**
     171     * course order ASC or DESC
     172     *
     173     * @callback_for 'scc_order' field
     174     */
     175    public function course_order() {
     176
     177        // set default option value
     178        $default = array( 'scc_order' => 'ASC' );
     179        $options = get_option( 'course_display_settings', $default );
     180        $options = wp_parse_args( $options, $default );
     181
     182        // possible list options
     183        $order = array(
     184            'asc'  => array( 'value' => 'asc', 'desc' => __( 'Ascending', 'scc' ) ),
     185            'desc' => array( 'value' => 'desc', 'desc' => __( 'Descending', 'scc' ) ),
     186        );
     187        ?>
     188        <select id="scc_order" name="course_display_settings[scc_order]">
     189            <?php foreach ( $order as $o ) { // display options from $order array ?>
     190                <option value="<?php echo $o['value']; ?>" <?php selected( $options['scc_order'], $o['value'] ); ?>><?php echo $o['desc']; ?></option>
     191            <?php } ?>
     192        </select>
     193        <label><?php _e( 'Choose whether your list should be in ascending or descending order.', 'scc' ); ?></label>
    163194        <?php
    164195    }
     
    178209        $options = wp_parse_args( $options, $default );
    179210
    180         // possible list style options
     211        // possible list options
    181212        $current_post = array(
    182213            'none'   => array( 'value' => 'none', 'desc' => __( 'No Style', 'scc' ) ),
     
    241272        } else {
    242273            update_option( 'scc_orderby', $input['scc_orderby'] );
     274        }
     275
     276        // validate the order option
     277        if ( ! isset( $input['scc_order'] ) ) {
     278            $input['scc_order'] = 'ASC';
     279        } else {
     280            update_option( 'scc_order', $input['scc_order'] );
    243281        }
    244282
  • simple-course-creator/trunk/includes/scc_templates/scc-output.php

    r1443528 r2270322  
    77// get/set the option values
    88$default_options = array(
    9     'display_position'  => 'above',
    10     'list_type'         => 'ordered',
    11     'scc_orderby'       => 'date',
    12     'current_post'      => 'none',
    13     'disable_js'        => 0,
     9    'display_position' => 'above',
     10    'list_type'        => 'ordered',
     11    'scc_orderby'      => 'date',
     12    'scc_order'        => 'ASC',
     13    'current_post'     => 'none',
     14    'disable_js'       => 0,
    1415);
    15 $options = get_option( 'course_display_settings', $default_options );
    16 $options = wp_parse_args( $options, $default_options );
     16$options         = get_option( 'course_display_settings', $default_options );
     17$options         = wp_parse_args( $options, $default_options );
    1718
    1819// build the post listing based on course
    19 $the_posts  = get_posts( array(
     20$the_posts     = get_posts( array(
    2021    'post_type'         => 'post',
    2122    'posts_per_page'    => -1,
     
    2324    'no_found_rows'     => true,
    2425    'orderby'           => $options['scc_orderby'],
    25     'order'             => apply_filters( 'scc_order', 'ASC' ),
     26    'order'             => $options['scc_order'],
    2627    'tax_query'         => array(
    2728        array( 'taxonomy' => 'course', 'field' => 'slug', 'terms' => $course->slug )
    2829) ) );
     30
    2931$course_toggle = apply_filters( 'course_toggle', __( 'full course', 'scc' ) );
    30 $posts = 1;
     32$posts         = 1;
     33
    3134foreach ( $the_posts as $post_id ) {
    3235    if ( $post_id == $post->ID ) break; $posts ++;
    3336}
    34 $array = get_option( 'taxonomy_' . $course->term_id );
    35 $post_list_title = $array['post_list_title'];
     37
     38$array              = get_option( 'taxonomy_' . $course->term_id );
     39$post_list_title    = $array['post_list_title'];
    3640$course_description = term_description( $course->term_id, 'course' );
    37 $list_container = $options['list_type'] == 'ordered' ? 'ol' : 'ul';
    38 $no_list = $options['list_type'] == 'none' ? 'style="list-style: none;"' : '';
     41$list_container     = $options['list_type'] == 'ordered' ? 'ol' : 'ul';
     42$no_list            = $options['list_type'] == 'none' ? 'style="list-style: none;"' : '';
     43
    3944switch ( $options['current_post'] ) {
    4045    case 'bold':
     
    7984 *          add_filter( 'course_toggle', 'your_filter_name' );
    8085 */
    81 ?>
    8286
    83 <?php if ( is_single() && sizeof( $the_posts ) > 1 ) :
     87if ( is_single() && sizeof( $the_posts ) > 1 ) :
    8488    do_action( 'scc_before_container' );
    8589    ?>
     
    132136        </div>
    133137        <?php do_action( 'scc_container_bottom' ); ?>
    134     </div>
    135 <?php
     138    </div><!-- #scc-wrap -->
     139    <?php
    136140do_action( 'scc_after_container' );
    137141endif;
  • simple-course-creator/trunk/includes/scc_templates/scc.css

    r919556 r2270322  
    11/**
    2  * To edit, create a folder called "scc_templates" in the root of your theme 
     2 * To edit, create a folder called "scc_templates" in the root of your theme
    33 * and COPY this file into it. It will override the plugin's CSS file.
    44 */
     
    77#scc-wrap {
    88    position: relative;
    9     padding: 1em;
    10     border: 1px solid #dadada;
    11     margin: 0 0 1.5em;
     9    padding: 1em 0 1.4em;
     10    border-width: 2px 0;
     11    border-style: dotted;
     12    border-color: rgba(0,0,0,.1);
     13    margin-bottom: 1.5em;
    1214}
    1315#scc-wrap .scc-post-container {
     
    4446#scc-wrap .scc-toggle-post-list {
    4547    position: absolute;
    46         right: 10px;
    47         bottom: 2px;
     48        right: 0;
     49        bottom: 10px;
    4850    font-size: 10px;
    4951    font-weight: bold;
Note: See TracChangeset for help on using the changeset viewer.