-4

最后一行是它不起作用的地方。我不知道应该去那里而不是$post.

    if (isset($_COOKIE["WP-LastViewedPosts"])) {
    //echo "Cookie was set.<br/>";  // For bugfixing - uncomment to see if cookie was set
    //echo $_COOKIE["WP-LastViewedPosts"]; // For bugfixing (cookie content)
    $zg_post_IDs = unserialize(preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", stripslashes($_COOKIE["WP-LastViewedPosts"]))); // Read serialized array from cooke and unserialize it
    foreach ($zg_post_IDs as $value) { // Do output as long there are posts
        global $wpdb;
        $zg_get_title = $wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE ID = '$value+0' LIMIT 1");
        foreach($zg_get_title as $post) {
            echo "<a href=\"". get_permalink($value+0) . "\" title=\"". apply_filters('the_title',$post->post_title) . "\">". apply_filters('the_title',$post->post_title) . "</a> \n"; // Output link and title
            echo implode(', ', $post);
        }
    }
4

1 回答 1

2

根据您的评论,一种方法是:

foreach ($zg_get_title as $post) 
{
    $title = apply_filters('the_title', $post->post_title);
    $posts[] = '<a href="'.get_permalink($value).'" title="'.$title.'">'.$title.'</a>';
}

echo implode(', ', $posts);
于 2012-10-12T12:58:56.367 回答