0

First let me say that I have been working on this issue for about 2 weeks and I have looked all over the place for an answer. Ive gone to various forums, blogs, the WordPress Codex and just about any and all places I could find. I still cannot get this to work properly. As a last resort I am coming here to see if maybe someone can assist me with it.

My issue is this. I am building a free Wordpress theme, http://wp-awesome.themeawesome.com. I will be submitting it to the WordPress Theme Repository and hopefully get it hosted so people can download it. One of the requirements is that a theme cannot generate any errors. Everything is working perfectly and there are no errors except one. I get the following error message when I go to a second page:

*Notice: Undefined variable: do_not_duplicate in /--/--/--/--/--/--/wp-awesome/index.php on line 68*

As you can see on the front page there is a featured post slider. This slider is will display posts that are tagged "featured". I am using the following code for this specific query:

    <?php 
            $mytag = mytheme_option( 'featured_tag' );
            $thecount = mytheme_option( 'featured_count' );
            $my_query = new WP_Query("tag=$mytag&showposts=$thecount");
            while ($my_query->have_posts()) : $my_query->the_post();
            $do_not_duplicate[] = $post->ID;
        ?>

// post stuff here

<?php endwhile; ?>

Now obviously on the home page I do not want the posts that are displaying in the slider to display on the front page in the regular loop below it. So i found the following code that seems to work great:

    <?php 
if (is_home()) { 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts(array(
        'post__not_in' => $do_not_duplicate,
        'paged' => $paged
    )); }
if (have_posts()) : while (have_posts()) : the_post(); ?>

// post stuff

<?php endwhile; ?>

the only problem is when you click on another page at the bottom the error shows up:

*Notice: Undefined variable: do_not_duplicate in /--/--/--/--/--/--/wp-awesome/index.php on line 68*

I know the error is appearing because when you go to a second or third page, there is nothing defining the do_not_duplicate param. Any ideas how to fix this?

Any help is greatly appreciated and I thank you in advance.

4

1 に答える 1

0

wp-content/themes/YOUR_THEME/header.php. 配列の場合は、要素を宣言する必要がある場合があります。このような:

<?php
  //  declaration of $do_not_duplicate array
  for ( $i = 0; $i < 100; $i++ ) {
    $do_not_duplicate[$i] = 0;
  };
?>
于 2012-08-25T18:58:55.677 に答える