[外掛]不用4image也可展示隨機圖片了

phpBB 2 MOD Support
無論是官方或非官方認證之外掛,安裝與使用問題討論。
(發表文章請按照公告格式發表,違者砍文)

版主: 版主管理群

主題已鎖定
WRSU
星球普通子民
星球普通子民
文章: 3
註冊時間: 2003-06-05 10:51

[外掛]不用4image也可展示隨機圖片了

文章 WRSU »

我以plus 1.0裡的相簿藝廊 為基本改造首頁,可以隨機展示相簿藝廊裡的圖片,如果有需要可以跟各位交流如何改造首頁 :lol:
DEMO
Kangu
版務實習幹部
版務實習幹部
文章: 44
註冊時間: 2002-06-18 10:13

文章 Kangu »

不錯耶...是把相簿裡面的那個秀最新圖片的程式碼放到PORTAL.PHP裡面改成兩張嗎?^^?
WRSU
星球普通子民
星球普通子民
文章: 3
註冊時間: 2003-06-05 10:51

文章 WRSU »

沒錯 :mrgreen:

\n各位如果有興趣可先嘗試更改相簿藝廊裡的最新圖片顯示
更改步驟如下

代碼: 選擇全部

1.打開 album.php
2.尋找\r
   
/*
+----------------------------------------------------------
| Recent Public Pics
+----------------------------------------------------------
*/
下面有兩行行

     ORDER BY pic_time DESC
    LIMIT ". $album_config['cols_per_page'];
把他取代成

     ORDER BY rand()
    LIMIT 2


ORDER BY rand() 是隨機排序
LIMIT 2 是限制輸出兩張

這樣就可已變成隨機展示圖片了
不過有個前提就是你的php必須是最新的,舊版的好像不支援。
以上資訊來是phpbb原始網站討論區
頭像
applelee
星球普通子民
星球普通子民
文章: 2
註冊時間: 2002-04-04 20:23
聯繫:

Re: [外掛]不用4image也可展示隨機圖片了

文章 applelee »

WRSU 寫:我以plus 1.0裡的相簿藝廊 為基本改造首頁,可以隨機展示相簿藝廊裡的圖片,如果有需要可以跟各位交流如何改造首頁 :lol:
DEMO
請問可以提供完整ㄉ教學嗎?謝謝!
WRSU
星球普通子民
星球普通子民
文章: 3
註冊時間: 2003-06-05 10:51

文章 WRSU »

以下程式碼源自 album.php 和 album_index_body.tpl,或許大家有更好的方法,歡迎大家一起討論。
程式碼部分僅修改前面一篇提到部分
請注意:修改之前請將原程式作備份!!
修改步驟如下
1.開啟 portal.php
2.尋找
//
// Start output of page
//

3.在這之前貼入以下程式碼\r

代碼: 選擇全部


//start random photo

//
// Get general album information
//

$album_root_path = $phpbb_root_path . 'album_mod/';
include($album_root_path . 'album_common.'.$phpEx);


/*
+----------------------------------------------------------
| Build Categories Index
+----------------------------------------------------------
*/

$sql = "SELECT c.*, COUNT(p.pic_id) AS count
		FROM ". ALBUM_CAT_TABLE ." AS c
			LEFT JOIN ". ALBUM_TABLE ." AS p ON c.cat_id = p.pic_cat_id
		WHERE cat_id <> 0
		GROUP BY cat_id
		ORDER BY cat_order ASC";
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
}

$catrows = array();

while( $row = $db->sql_fetchrow($result) )
{
	$album_user_access = album_user_access($row['cat_id'], $row, 1, 0, 0, 0, 0, 0); // VIEW
	if ($album_user_access['view'] == 1)
	{
		$catrows[] = $row;
	}
}

$allowed_cat = ''; // For Recent Public Pics below

//
// $catrows now stores all categories which this user can view. Dump them out!
//
for ($i = 0; $i < count($catrows); $i++)
{
	// --------------------------------
	// Build allowed category-list (for recent pics after here)
	// --------------------------------
	
	$allowed_cat .= ($allowed_cat == '') ? $catrows[$i]['cat_id'] : ',' . $catrows[$i]['cat_id'];

	
	// --------------------------------
	// Build moderators list
	// --------------------------------

	$l_moderators = '';
	$moderators_list = '';

	$grouprows= array();

	if( $catrows[$i]['cat_moderator_groups'] != '')
	{
		// We have usergroup_ID, now we need usergroup name
		$sql = "SELECT group_id, group_name
\n				FROM " . GROUPS_TABLE . "
				WHERE group_single_user <> 1
					AND group_type <> ". GROUP_HIDDEN ."
					AND group_id IN (". $catrows[$i]['cat_moderator_groups'] .")
				ORDER BY group_name ASC";
		if ( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain usergroups data', '', __LINE__, __FILE__, $sql);
		}

		while( $row = $db->sql_fetchrow($result) )
		{
			$grouprows[] = $row;
		}
	}

	if( count($grouprows) > 0 )
	{
		$l_moderators = $lang['Moderators'];

		for ($j = 0; $j < count($grouprows); $j++)
		{
			$group_link = '<a href="'. append_sid("groupcp.$phpEx?". POST_GROUPS_URL .'='. $grouprows[$j]['group_id']) .'">'. $grouprows[$j]['group_name'] .'</a>';

			$moderators_list .= ($moderators_list == '') ? $group_link : ', ' . $group_link;
		}		
	}

	
	// ------------------------------------------
	// Get Last Pic of this Category
	// ------------------------------------------

	if ($catrows[$i]['count'] == 0)
	{
		//
		// Oh, this category is empty
		//
		$last_pic_info = $lang['No_Pics'];
		$u_last_pic = '';
		$last_pic_title = '';
	}
	else
	{
		// ----------------------------
		// Check Pic Approval
		// ----------------------------

		if(($catrows[$i]['cat_approval'] == ALBUM_ADMIN) or ($catrows[$i]['cat_approval'] == ALBUM_MOD))
		{
			$pic_approval_sql = 'AND p.pic_approval = 1'; // Pic Approval ON
		}
		else
		{
			$pic_approval_sql = ''; // Pic Approval OFF
		}

		
		// ----------------------------
		// OK, we may do a query now...
		// ----------------------------

		$sql = "SELECT p.pic_id, p.pic_title, p.pic_user_id, p.pic_username, p.pic_time, p.pic_cat_id, u.user_id, u.username
				FROM ". ALBUM_TABLE ." AS p	LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
				WHERE p.pic_cat_id = '". $catrows[$i]['cat_id'] ."' $pic_approval_sql
				ORDER BY p.pic_time DESC
				LIMIT 1";
		if ( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not get last pic information', '', __LINE__, __FILE__, $sql);
		}
		$lastrow = $db->sql_fetchrow($result);


		// ----------------------------
		// Write the Date
		// ----------------------------
		
		$last_pic_info = create_date($board_config['default_dateformat'], $lastrow['pic_time'], $board_config['board_timezone']);

		$last_pic_info .= '<br />';


		// ----------------------------
		// Write username of last poster
		// ----------------------------
		
		if( ($lastrow['user_id'] == ALBUM_GUEST) or ($lastrow['username'] == '') )
		{
			$last_pic_info .= ($lastrow['pic_username'] == '') ? $lang['Guest'] : stripslashes($lastrow['pic_username']);
		}
		else
		{
			$last_pic_info .= $lang['Poster'] .': <a href="'. append_sid("profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $lastrow['user_id']) .'">'. $lastrow['username'] .'</a>';
		}


		// ----------------------------
		// Write the last pic's title. 
		// Truncate it if it's too long
		// ----------------------------
	
		if( !isset($album_config['last_pic_title_length']) )
		{
			$album_config['last_pic_title_length'] = 25;
		}

		$lastrow['pic_title'] = stripslashes($lastrow['pic_title']);

		if (strlen($lastrow['pic_title']) > $album_config['last_pic_title_length'])
		{
			$lastrow['pic_title'] = substr($lastrow['pic_title'], 0, $album_config['last_pic_title_length']) . '...';
		}

		$last_pic_info .= '<br />'. $lang['Pic_Title'] .': <a href="';

		$last_pic_info .= ($album_config['fullpic_popup']) ? append_sid("album_pic.$phpEx?pic_id=". $lastrow['pic_id']) .'" target="_blank">' : append_sid("album_page.$phpEx?pic_id=". $lastrow['pic_id']) .'">' ;

		$last_pic_info .= $lastrow['pic_title'] .'</a>';
	}
	// END of Last Pic

}
// END of Categories Index


/*
+----------------------------------------------------------
| Recent Public Pics
+----------------------------------------------------------
*/

if ($allowed_cat != '')
{
	$sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_view_count, u.user_id, u.username, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments
			FROM ". ALBUM_TABLE ." AS p				
				LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
				LEFT JOIN ". ALBUM_CAT_TABLE ." AS ct ON p.pic_cat_id = ct.cat_id
				LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
				LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
			WHERE p.pic_cat_id =2 
			GROUP BY p.pic_id
			ORDER by rand()
			LIMIT 2";
	if( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not query recent pics information', '', __LINE__, __FILE__, $sql);
	}

	$recentrow = array();

	while( $row = $db->sql_fetchrow($result) )
	{
		$recentrow[] = $row;
	}


	if (count($recentrow) > 0)
	{
		for ($i = 0; $i < count($recentrow); $i += $album_config['cols_per_page'])
		{
			$template->assign_block_vars('recent_pics', array());

			for ($j = $i; $j < ($i + $album_config['cols_per_page']); $j++)
			{
				if( $j >= count($recentrow) )
				{
					break;
				}

				if(!$recentrow[$j]['rating'])
				{
					$recentrow[$j]['rating'] = $lang['Not_rated'];
				}
				else
				{
					$recentrow[$j]['rating'] = round($recentrow[$j]['rating'], 2);
				}

				$template->assign_block_vars('recent_pics.recent_col', array(
					'U_PIC' => ($album_config['fullpic_popup']) ? append_sid("album_pic.$phpEx?pic_id=". $recentrow[$j]['pic_id']) : append_sid("album_page.$phpEx?pic_id=". $recentrow[$j]['pic_id']),
					'THUMBNAIL' => append_sid("album_thumbnail.$phpEx?pic_id=". $recentrow[$j]['pic_id']),
					'DESC' => stripslashes($recentrow[$j]['pic_desc'])
					)
				);

				if( ($recentrow[$j]['user_id'] == ALBUM_GUEST) or ($recentrow[$j]['username'] == '') )
				{
					$recent_poster = ($recentrow[$j]['pic_username'] == '') ? $lang['Guest'] : stripslashes($recentrow[$j]['pic_username']);
				}
				else
				{
					$recent_poster = '<a href="'. append_sid("profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $recentrow[$j]['user_id']) .'">'. $recentrow[$j]['username'] .'</a>';
				}

				$template->assign_block_vars('recent_pics.recent_detail', array(
					'TITLE' => stripslashes($recentrow[$j]['pic_title']),
					'POSTER' => $recent_poster,
					'TIME' => create_date($board_config['default_dateformat'], $recentrow[$j]['pic_time'], $board_config['board_timezone']),

					'VIEW' => $recentrow[$j]['pic_view_count'],

					'RATING' => ($album_config['rate'] == 1) ? ( '<a href="'. append_sid("album_rate.$phpEx?pic_id=". $recentrow[$j]['pic_id']) . '">' . $lang['Rating'] . '</a> : ' . $recentrow[$j]['rating'] . '<br />') : '',

					'COMMENTS' => ($album_config['comment'] == 1) ? ( '<a href="'. append_sid("album_comment.$phpEx?pic_id=". $recentrow[$j]['pic_id']) . '">' . $lang['Comments'] . '</a> : ' . $recentrow[$j]['comments'] . '<br />') : '',

					'IP' => ($userdata['user_level'] == ADMIN) ? $lang['IP_Address'] . ': <a href="http://www.nic.com/cgi-bin/whois.cgi?query=' . decode_ip($recentrow[$j]['pic_user_ip']) . '" target="_blank">' . decode_ip($recentrow[$j]['pic_user_ip']) .'</a><br />' : ''
					)
				);
			}
		}
	}
	else
	{
		//
		// No Pics Found
		//
		$template->assign_block_vars('no_pics', array());
	}
}
else
{
	//
	// No Cats Found
	//
	$template->assign_block_vars('no_pics', array());
}




$template->set_filenames(array(
	'body' => 'portal_body.tpl')
);
$template->assign_vars(array(
	'L_CATEGORY' => $lang['Category'],
	'L_PICS' => $lang['Pics'],
	'L_LAST_PIC' => $lang['Last_Pic'],

	'U_YOUR_PERSONAL_GALLERY' => append_sid("album_personal.$phpEx?user_id=". $userdata['user_id']),
	'L_YOUR_PERSONAL_GALLERY' => $lang['Your_Personal_Gallery'],

	'U_USERS_PERSONAL_GALLERIES' => append_sid("album_personal_index.$phpEx"),
	'L_USERS_PERSONAL_GALLERIES' => $lang['Users_Personal_Galleries'],

	'S_COLS' => $album_config['cols_per_page'],
	'S_COL_WIDTH' => (100/$album_config['cols_per_page']) . '%',
	'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
	'L_RECENT_PUBLIC_PICS' => $lang['Recent_Public_Pics'],
	'L_NO_PICS' => $lang['No_Pics'],
	'L_PIC_TITLE' => $lang['Pic_Title'],
	'L_VIEW' => $lang['View'],
	'L_POSTER' => $lang['Poster'],
	'L_POSTED' => $lang['Posted'],
	'L_PUBLIC_CATS' => $lang['Public_Categories'])
);



//end random photo

4.開啟 portal_body.tpl
5.尋找你要放入隨機圖片的位置放入以下程式碼\r
比方DEMO網站當中
你可取代原本歡迎光臨位置的表格部分即可\r

代碼: 選擇全部

<table width="96%" cellpadding="2" align="center" cellspacing="1" border="0" class="forumline">
  <tr>
	<th class="thTop" height="25" colspan="{S_COLS}" nowrap="nowrap"><span class="genmed">社區寶寶秀</th>
  </tr>
  <!-- BEGIN no_pics -->
  <tr>
	<td class="row1" align="center" colspan="{S_COLS}" height="50"><span class="gen">{L_NO_PICS}</span></td>
  </tr>
  <!-- END no_pics -->
  <!-- BEGIN recent_pics -->
  <tr>
  <!-- BEGIN recent_col -->
	<td class="row1" width="{S_COL_WIDTH}" align="center"><a href="{recent_pics.recent_col.U_PIC}" {TARGET_BLANK}><img src="{recent_pics.recent_col.THUMBNAIL}" border="0" alt="{recent_pics.recent_col.DESC}" title="{recent_pics.recent_col.DESC}" vspace="10" /></a></td>
  <!-- END recent_col -->
  </tr>
  <tr>
  <!-- BEGIN recent_detail -->
    <td class="row2" align="center" ><span class="gensmall"> {recent_pics.recent_detail.TITLE}<br />
  </span>
	</td>
  <!-- END recent_detail -->
  </tr>
  <!-- END recent_pics -->
  <tr>
  <td   colspan=2 align="center"> 
  <a href="http://140.115.60.178/hiyuen/album_cat.php?cat_id=2">認識更多社區可愛寶寶</a>
 </td>
  </tr>
</table>
6.完成
頭像
applelee
星球普通子民
星球普通子民
文章: 2
註冊時間: 2002-04-04 20:23
聯繫:

文章 applelee »

謝謝你ㄉ教導...
sakamoto
版面管理員
版面管理員
文章: 350
註冊時間: 2003-02-13 17:36
來自: scratch
聯繫:

文章 sakamoto »

奇怪我弄好了..但卻顯示"沒有照片"...我有上傳一堆照片耶.....
吉川拓也
竹貓忠實會員
竹貓忠實會員
文章: 1215
註冊時間: 2003-02-09 18:24
來自: [ G.I.T ]
聯繫:

文章 吉川拓也 »

sakamoto 寫:奇怪我弄好了..但卻顯示"沒有照片"...我有上傳一堆照片耶.....
真柄大 ~
你看這部分 :

代碼: 選擇全部

WHERE p.pic_cat_id =2 
         GROUP BY p.pic_id 
         ORDER by rand() 
         LIMIT 2"; 
他的預設版面是 : WHERE p.pic_cat_id =2
你應該是要設定跟你版面一樣才能顯示呢 !!
善用 搜尋 可以解決您 90% 的問題
頭腦清晰,選擇正確。 (╯▔︹▔)╯~╘═╛
主題已鎖定

回到「外掛問題討論」