• Resolved Lane Lester

    (@llester)


    I’ve tried a bunch of responsive slider plugins without success. Only one is working for me: Responsive Slider. However, for the maximum number of slides in a slider, it uses the Maximum-Posts-Per-Page setting in the Reading page.

    Is there a way to change that setting during the execution of the plugin and then set it back after the plugin is through?

    In my naivete, I tried this at the beginning of the plugin’s PHP file:

    $temppp = $posts_per_page;
    $posts_per_page = 10;

    and at the bottom I put:
    $posts_per_page = $temppp;

    But I still got only two slides, the setting in Reading.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    (@alchymyth)

    ‘posts_per_page’ is saved as an option;

    try (untested; will depend on the location where you add the lines into the plugin’s code):

    $temppp = get_option( 'posts_per_page' );
    update_option( 'posts_per_page', 10 );
    
    /*SLIDER*/
    
    update_option( 'posts_per_page', $temppp );

    https://codex.www.ads-software.com/Function_Reference/get_option
    https://codex.www.ads-software.com/Function_Reference/update_option

    Thread Starter Lane Lester

    (@llester)

    Thanks for the suggestion! It seems no matter where I put it, it generates an error at the next function. Here’s an example bit of code:

    /* Set max-posts-per-page option */
    $temppp = get_option( 'posts_per_page' );
    update_option( 'posts_per_page', 10 );
    
    /**
     * Do things on plugin activation.
     *
     * @since 0.1
     */
    function responsive_slider_activation() {

    The last line is 102, and this is the error:

    Parse error: syntax error, unexpected T_FUNCTION, expecting T_STRING or T_VARIABLE or ‘$’ in /home/jmountai/public_html/the/wp-content/plugins/responsive-slider/responsive-slider.php on line 102

    Thread Starter Lane Lester

    (@llester)

    I just stuck the code inside and at the end of a previous function: function responsive_slider_setup()

    I got a different kind of error then:

    Parse error: syntax error, unexpected ‘}’, expecting T_STRING or T_VARIABLE or ‘$’ in /home/jmountai/public_html/the/wp-content/plugins/responsive-slider/responsive-slider.php on line 96

    Line 96 is the closing } for that function.

    Thread Starter Lane Lester

    (@llester)

    I tried putting the code inside the function that does the main job:

    function responsive_slider($id = 0) {
    
    /* Set max-posts-per-page option */
    $temppp = get_option( 'posts_per_page' );
    update_option( 'posts_per_page', 10 );
    
    	$slides = new WP_Query( array( 'post_type' => 'slides', 'order' => 'ASC', 'orderby' => 'menu_order', 'meta_key' => '_slider_id', 'meta_value' => $id ) );

    The error generated was:

    Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in /home/jmountai/public_html/the/wp-content/plugins/responsive-slider/responsive-slider.php on line 244

    Line 244 is the last line in the code above.

    Michael

    (@alchymyth)

    this is the main function, where the number of post could be set directly into the query args:
    in responsive-slider.php (line 237, about one-third down)

    function responsive_slider() {
    
    	$slides = new WP_Query( array( 'post_type' => 'slides', 'order' => 'ASC', 'orderby' => 'menu_order' ) );

    the easiest way is probably to forget to minipulate the ‘posts_per_page’ options, but to add the number of posts directly into the code:

    function responsive_slider() {
    
    	$slides = new WP_Query( array( 'post_type' => 'slides', 'order' => 'ASC', 'orderby' => 'menu_order', 'posts_per_page' => 10 ) );
    Thread Starter Lane Lester

    (@llester)

    Am I ever embarrassed! I copied the code directly from this web page and pasted it into the PHP file. The single quote was converted to the &# code, and that was what was generating the errors.

    Your original code works just fine. I went ahead and tried your simplied solution, and it works as well.

    Thank you so much for this help. I was beginning to despair of finding a responsive slider that would work.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to Change Maximum-Posts-Per-Page Setting in Plugin’ is closed to new replies.