• Resolved Friar

    (@friar)


    I’d like to display a couple of these link widgets on my page. Top one will have a list of 5, the lower one will have a list of 5. I’d like to place something else in between them, and have the links on the upper and lower widgets remain in chronological order. So if I go in and add a few new links, they get added to the top widget, and the others cycle down to the lower widget.

    If I can set the lower one to skip the first 5 links, I think this could work, I just can’t find a setting to do that.

    I know I could manually go in and re-categorize the links individually and get them to move down, but this thing gets 20-30 new links per day placed in it, and it would be too much work to manually re-categorize them one at a time to preserve the link order between the 2 widgets. An offset would perfectly if available.

    https://wordpress.org/plugins/simple-links/

Viewing 1 replies (of 1 total)
  • Plugin Author Mat Lipe

    (@mat-lipe)

    Hello Friar,

    There is no way out the box to do this. However you may tap in to built in filters to accomplish this.

    If you add this code to your active theme’s functions.php file, it should add an offset field to the bottom of the widget and use it setting.

    add_action( 'simple_links_widget_form', 'sl_offset', 9, 2 );
    if( !function_exists( 'sl_offset' ) ){
        function sl_offset( $instance, \WP_Widget $object ){
            $instance[ 'offset' ] = empty( $instance[ 'offset' ] ) ? 0 : $instance[ 'offset' ];
            ?>
            <strong>Offset</strong>
            <input type="number" id="<?php echo $object->get_field_id( 'offset' ); ?>" name="<?php echo $object->get_field_name( 'offset' ); ?>" value="<?php echo esc_attr( $instance[ 'offset' ] ); ?>" class="widefat"/>
            <?php
    
        }
    }
    
    add_filter( 'simple_links_parsed_query_args', 'sl_allow_offset', 1, 2 );
    function sl_allow_offset( $args, \SimpleLinksFactory $object ){
        if( !empty( $object->args[ 'offset' ] ) ){
            $args[ 'offset' ]      = (int) $object->args[ 'offset' ];
            $args[ 'numberposts' ] = $args[ 'numberposts' ] == - 1 ? 1000000 : $args[ 'numberposts' ];
        }
    
        return $args;
    }
Viewing 1 replies (of 1 total)

The topic ‘Is There an Offset Possible?’ is closed to new replies.