实现implode时出错,用php爆炸数组

时间:2014-10-21 08:05:21

标签: php arrays wordpress dynamic-arrays

我有这个代码,从我的单词press db中选择文章内容,然后使用循环将其输出到表格中。一旦用户选择他们喜欢的文章,他们将选择提交到我的下一页,将其称为显示页面以显示所选文章。

选择页面代码如下所示。

        <?php /*
    Template Name: News Selector Template
    */
      //Pull the data
    $posts = $wpdb->get_results
    ("
    SELECT
        p1.*,
        wm2.meta_value 
    FROM
        mp_posts p1 
    LEFT JOIN
        mp_postmeta wm1
        ON (
            wm1.post_id = p1.id
            AND wm1.meta_value IS NOT NULL
            AND wm1.meta_key = '_thumbnail_id'
        )
    LEFT JOIN
        mp_postmeta wm2
        ON (
            wm1.meta_value = wm2.post_id
            AND wm2.meta_key = '_wp_attached_file'
            AND wm2.meta_value IS NOT NULL
        )
    WHERE
        p1.post_status='publish'
        AND p1.post_type='post'
    ORDER BY
        p1.post_date DESC LIMIT 0,30
    ");

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <div class="container">
      <div class="header"><a href="mpasho.co.ke"><img src="/sample/images/logo_main_300x100px.png" alt="logo" name="sample_logo" width="300" height="100" id="logo" style="background-color: #FFF; display:block;" /></a> 
        <!-- end .header --></div>
      <div class="content">
        <h1>sample Top 30 Articles</h1>
        <p>Select the articles you want to add to the newsletter</p>
         <form action="http://sample.net/brands/sample/newsletter/"  method="post">
        <table width="960" border="2" summary="A collection of all the articles">
          <caption>
          Article Selection
          </caption>
        <tr>
        <th scope="col">Select</th>
        <th scope="col">Title</th>
        <th scope="col">Description</th>
        <th scope="col">Cover</th>
        <th scope="col">link</th>
          </tr>
          <?php
          // if(isset($_POST['submit'])){
           if (have_posts($posts)) {
          // var_dump($posts); die();
          foreach($posts as $post) {     
           //foreach($_POST['article_list'] as $post){       
            ?>
            <tr>
              <th scope="row"><input type="checkbox" name="article[]" value="<?php echo $post->ID; ?>" /></th>
              <td headers="article[]"><?php echo $post->post_title; ?></td>
              <td headers="article[]"><?php echo $post->post_excerpt; ?></td>
              <td headers="article[]"><?php echo '<img src="https://sample/wp-content/uploads/'.$post->meta_value.'" width="100px" alt="" />'?></td>
              <td headers="article[]"><?php echo $post->guid; ?></td>
            </tr>
          <?php 
          }
         }

          ?>
        <p><input type="hidden" name="metas" value="<?php echo implode(",", $post); ?>"></p>
        </table>
       <div>
        <p><input type="submit" name="Generate"  value="submit"/></p>

        </div>
        </form>
        <!---->
        </div>
       <!-- end .content --></div>
      <div class="footer">
        <p>sample Management System</p>
        <!-- end .footer --></div>
      <!-- end .container --></div>
    </body>
    </html>

Iv使用implode通过复选框选项收集所有选定文章的数组变量。

在我的显示页面上,我编写了这个简单的代码来查看数组的输出。

        <?php /*
    Template Name: Newsletter Template
    */

    $posts = explode(",", $_POST['metas']);

    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>

    <body>
    <?php echo $posts[0]->guid ?>
    <?php echo $posts[0]->meta_value ?>
    <?php echo $posts[0]->post_title ?>
    <?php echo $posts[0]->post_excerpt ?>
    </body>
    </html>

现在,当我从第一页提交所选文章时,我应该能够访问显示页面中的各种数组元素,但事实并非如此。我得到了 ERROR

  

警告:implode():传入的参数无效   /home/sampled/public_html/brands/sample/wp-content/themes/newsample/page-newsselector.php   在第164行

我不知道我的实施在哪里出错了。

请帮助

0 个答案:

没有答案