WordPress.org

Ready to get started?Download WordPress

Forums

Complete script appears in Plugin Management list? (5 posts)

  1. glasgowd
    Member
    Posted 7 years ago #

    Hi--

    WordPress newbie here, so I'm sure I'm missing something. I just copied the code from <http://wordpress.org/support/topic/11211?replies=21#post-67536>, pasted it into a new PHP document, and uploaded it to my wp-content/plugins folder. So far, so good.

    Except that when I view the plugin in my Plugin Management list, instead of neat cells of plugin name, version, and description, I see large chunks of the actual plugin script itself. I'm afraid to activate the plug-in, lest I screw something up.

    I've compared the syntax and formatting of the script to the hello.php that came with the WordPress install, and can't see any differences that look like they'd "break" anything, but ignorance rules the day over here.

    Any ideas what I might be doing wrong?

    Thanks in advance!

    : )
    David

  2. vkaryl
    Member
    Posted 7 years ago #

    Open that plugin in a vanilla text editor (notepad2 from flos-freeware.ch, phpedit, etc.) and make sure you have NO WHITE SPACE before the opening php tag, or after the closing php tag.

  3. glasgowd
    Member
    Posted 7 years ago #

    Well, the first line of the code is "<?php" (with no white space before it), and the last line is "?>" (with no white space after it....

  4. yosemite
    Member
    Posted 7 years ago #

    Look for the backticks you probably cut and pasted too.

  5. glasgowd
    Member
    Posted 7 years ago #

    Nope. Here's what's there in the file (again, with nothing before the first or after the last lines):

    <?php
    /*
    Plugin Name: Custom Posts Per Page
    Plugin URI: http://wordpress.org/#
    Description: Change the number of posts per page displayed for different page types.
    Author: Ryan Boren
    Version: 1.0
    Author URI: http://boren.nu/
    */

    $num_posts_on_home = 1;
    function custom_posts_per_page($query_string) {
    global $num_posts_on_home;
    $query = new WP_Query();
    $query->parse_query($query_string);
    if ($query->is_home) {
    if ($query_string != '') {
    $query_string .= '&';
    }
    $query_string .= "posts_per_page=$num_posts_on_home";
    }
    // Category example.
    // else if ($query->is_category) {
    // if ($query_string != '') {
    // $query_string .= '&';
    // }
    // $query_string .= "posts_per_page=$num_posts_in_category";
    // }
    return $query_string;
    }
    add_filter('query_string', 'custom_posts_per_page');

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic