WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_option(posts_per_page) deletes content (4 posts)

  1. Fike
    Member
    Posted 3 years ago #

    Hi.
    I want to dynamically add some space between posts (i mean, i want to add a blank div with some height after every post, except for the last one) and older posts/newer posts navilinks. This should be an easy task if i knew how many posts were set to show up in the settings panel. But when i add get_option(posts_per_page) function, content suddenly disappears from posts, leaving just blank forms. If i put it in a loop after the content is retrieved, only the first post is shown. What am i doing wrong?

  2. Dan Cole
    Member
    Posted 3 years ago #

    Are you using it like so:
    $posts_per_page = get_option('posts_per_page');

    The get_option returns a value, so you need to assign it to a variable.

    Are you putting single or double quotes around posts_per_page, because it is not the name of a PHP variable, it's a string?

    I think your getting a PHP error and that's breaking the page load for the rest of the page.

  3. Fike
    Member
    Posted 3 years ago #

    Are you using it like so:
    $posts_per_page = get_option('posts_per_page');

    The get_option returns a value, so you need to assign it to a variable.

    Are you putting single or double quotes around posts_per_page, because it is not the name of a PHP variable, it's a string?

    Yeah, but it worked when i've just copied your text - most possibly i've missed somewhere a letter. Thanks!

  4. Dan Cole
    Member
    Posted 3 years ago #

    Personally I would create a quick plugin that looks something like this:

    <?php
    /*
    Plugin Name: Fike_Extra_Space
    Plugin URI: http://wordpress.org/
    Description: Add extra space
    Version: 1.0
    */
    function fike_add_space() {
      echo "<div class='extra'></div>";
    }
    $fike = 1;
    while ( $fike < get_option('posts_per_page') ) {
      add_action('fike_add_space', 'in_the_loop_' . $fike);
    }
    ?>

    I haven't tested this code, but you'll get the basic idea. It should add that div tag to the first post through the 2nd to last post on every page, unless there is only one post on the page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags