HTML,CSS,PHP,ワードプレスカスタマイズ 技術情報資料

WelCartのデータを指定順で表示させる

WelcartAppend.php 内の Welcart My Ranking Option で
指定した順番でデータを表示させる場合のカスタマイズ。
※WelCart My Ranking のウィジェットを使用しない場合
※WelCart My Ranking で表示書式を指定できるようにすれば済む話だけど。
 
本来の以下のようなループ構造を
<!--- 本来のループ構造 --->
<?php query_posts($query_string . "&showposts=20"); ?>
<?php $count=1; if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--- ここまで --->


<!--- 表示モジュール --->


<?php endwhile; endif; ?>
 
以下のように直す。
<!--- ループ初期化 --->
<?php
	$rankdata = get_option('WelcartMyRanking_RankList');
	$rank_stk = preg_split('/,/', $rankdata);
	sort ( $rank_stk , SORT_NUMERIC );
	$rank_cnt=count($rank_stk);
	$rank_pos=1;
	if($rank_cnt<=0){
		$rank_pos=0;
	}
?>
<!--- ループ初期化 ここまで ---->


<!--- 本来のループ構造 --->
<?php query_posts($query_string . "&showposts=20"); ?>
<?php $count=1; if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--- ここまで --->


<!---- 挿入モジュール --->
<?php
	if($rank_pos>0){
		if($rank_pos<$rank_cnt){	
			$rk=preg_split('/<>/', $rank_stk[$rank_pos]);	/* 0:RANK 1:ID 2:pictID 3:cnt 4:mark */
			if( $rk[0] != '' ){
				$post = get_post($rk[1]);
			}
			$rank_pos++;
		}else{
			$skipf=1;
			while( $skipf==1 ){
				$check_id=get_the_ID();
				$skipf=0;
			 	foreach($rank_stk as $val){
					$rk=preg_split('/<>/', $val);	/* 0:RANK 1:ID 2:pictID 3:cnt 4:mark */
					if($rk[1]!=''){
						if($rk[1]==$check_id){
							the_post(); 
							$skipf=1;
							break;
						}
					}
				}
			}
		}
	}
?>
<!---- 挿入モジュール ここまで--->


<!--- 表示モジュール --->


<?php endwhile; endif; ?>
 
スナップショット用ブロック
<!-- スナップショット
<?php
echo "count=".$rank_cnt."<br />";
echo "stack0=".$rank_stk[0]."<br />";
echo "stack1=".$rank_stk[1]."<br />";
echo "stack2=".$rank_stk[2]."<br />";
 	foreach($rank_stk as $val){
		$rk=preg_split('/<>/', $val);	/* 0:RANK 1:ID 2:pictID 3:cnt 4:mark */
		echo "rk0=".$rk[0]." "."rk1=".$rk[1]."<br />";
	}
?>
-->

スポンサーリンク

関連記事

スポンサーリンク

カテゴリー