サポート » プラグイン » Last Viewed Posts 記事がない場合の記述について

  • 解決済 canberry

    (@canberry)


    Last Viewed Posts のプラグインで、初めてサイトに訪れる方などは
    記事の閲覧履歴などがないので、何も表示されない状態になります。
    何も表示されない場合に、何か1文を表示したいのですが、表示されず困っています。

    function zg_recently_viewed() { // Output
    	echo '<ul class="viewed_posts">';
    	if (isset($_COOKIE["WP-LastViewedPosts"])) {
    		//echo "Cookie was set.";  // 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 $zg_title_out) {
    				echo "
    <li><a>post_title . "\">". $zg_title_out->post_title . "</a></li>
    \n"; // Output link and title
    			}
    		}
    	} else {
    		echo "No cookie found.";  // For bugfixing - uncomment to see if cookie was not set
    	}
    	echo '';
    }

    ほぼデフォルトのままですが、現状このような状態で、
    「No cookie found.」が表示されるはずが、何も表示されません。

    ご教授の程、よろしくお願い致します。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • 試してみたところ No cookie found. が表示されましたよ。
    テーマのテンプレートに書いたのは下記の3行だけです。

    <?php if ( function_exists( 'zg_recently_viewed' ) ):
    	zg_recently_viewed();
    endif; ?>

    トピック投稿者 canberry

    (@canberry)

    そちらのコードを試したら、「No cookie found.」表示されました!

    <?php if (function_exists('zg_recently_viewed')):  if (isset($_COOKIE["WP-LastViewedPosts"])) { ?>
    <?php zg_recently_viewed(); ?>
    <?php }  endif; ?>

    私は上記のように記述していたので、それが原因でした・・・
    ありがとうございました!

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「Last Viewed Posts 記事がない場合の記述について」には新たに返信することはできません。