rss 뉴스갯수 조절 어떻게 하나요? 정보
rss 뉴스갯수 조절 어떻게 하나요?본문
뉴스 리스트가 20여개 나오는데요. 한 5개만 나오게 하고 싶어서요.. 리스트를 5개나 더 적은 갯수로 줄일려면 어찌 해야 하나요?
<?php
include_once("./_common.php");
$html_title = "news";
$g4[title] = "" . $html_title;
// 헤더화일 불러오기(상단메뉴와 왼쪽메뉴가 이곳에서 불러오겠죠)
include_once("$g4[path]/head.sub.php");
// rss library 불러오기 (그누보드 lib 디렉토리 화일에 rss.lib.php를 저장해두셔야합니다.)
include_once("lib/rss.lib.php");
// 회원외 접근금지 기능을 사용하시려면 주석을 제거하세요.
//if (!$member[mb_id]) {
// alert("회원이시라면 로그인 후 이용해 보십시오.", "./bbs/login.php");
// }
?>
<table width=374 cellpadding=0 cellspacing=0>
<tr>
<td style='padding:10px; line-height:150%;'><span class=small><br/>
</span></td>
</tr>
</table>
<!-- 공백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>
<!-- 검색 시작 -->
<form name=fnew method=get style="margin:0px;">
<table width="370" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"></td>
<td width="84" align="left"><img src="<?=$g4[path]?>/img/search/rss/rss_title.gif" /> </td>
<td width="230" height="20" align="left">
<input type=text id='channel_query' name='channel_query' maxlength='100' style='width:230px;height:20;' tabIndex=0 class=input_<?=$home_search_design?> trim onKeypress="if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) event.returnValue = false;" onpaste="return false;">
<input name="image" type=image src='<?=$g4[path]?>/img/search/rss/rss_search_btn.gif' />
</td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<?
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 네이버 뉴스 검색 RSS 주소입니다.
$channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
// 기본 검색어를 지정합니다. (각자 상황에 맞게) 예를 들어서 요즘 뜨고 있는 주식시장 코스피로 했습니다.
if($channel_query == '') {
$channel_query = "학원학교교육";
}
// 설정한 채널에서 검색된 뉴스를 읽어온다.
$Ynum = 5;//몇개를 보여줄것인지 셑팅하세요
$rss_array = rss_array($channel_list.$channel_query);
// 긁어온 RSS의 채널 태그의 타이틀을 네이버(UTF-8사용) euc-kr로 변환
// 서버 환경이 UTF-8일경우 iconv를 사용하지 않으면 됩니다.
$channel = $rss_array['channel']['title'];
$mt_cha =iconv("utf-8","euc-kr","$channel");
?>
<table width="350" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
} //foreach
echo("</table><p><div align=center></div><br></td></tr></table>");
} // 검색된 뉴스 갯수 IF
else {
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table><br></td></tr></table>");
}
?>
<?php
include_once("./_common.php");
$html_title = "news";
$g4[title] = "" . $html_title;
// 헤더화일 불러오기(상단메뉴와 왼쪽메뉴가 이곳에서 불러오겠죠)
include_once("$g4[path]/head.sub.php");
// rss library 불러오기 (그누보드 lib 디렉토리 화일에 rss.lib.php를 저장해두셔야합니다.)
include_once("lib/rss.lib.php");
// 회원외 접근금지 기능을 사용하시려면 주석을 제거하세요.
//if (!$member[mb_id]) {
// alert("회원이시라면 로그인 후 이용해 보십시오.", "./bbs/login.php");
// }
?>
<table width=374 cellpadding=0 cellspacing=0>
<tr>
<td style='padding:10px; line-height:150%;'><span class=small><br/>
</span></td>
</tr>
</table>
<!-- 공백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>
<!-- 검색 시작 -->
<form name=fnew method=get style="margin:0px;">
<table width="370" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"></td>
<td width="84" align="left"><img src="<?=$g4[path]?>/img/search/rss/rss_title.gif" /> </td>
<td width="230" height="20" align="left">
<input type=text id='channel_query' name='channel_query' maxlength='100' style='width:230px;height:20;' tabIndex=0 class=input_<?=$home_search_design?> trim onKeypress="if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) event.returnValue = false;" onpaste="return false;">
<input name="image" type=image src='<?=$g4[path]?>/img/search/rss/rss_search_btn.gif' />
</td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<?
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 네이버 뉴스 검색 RSS 주소입니다.
$channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
// 기본 검색어를 지정합니다. (각자 상황에 맞게) 예를 들어서 요즘 뜨고 있는 주식시장 코스피로 했습니다.
if($channel_query == '') {
$channel_query = "학원학교교육";
}
// 설정한 채널에서 검색된 뉴스를 읽어온다.
$Ynum = 5;//몇개를 보여줄것인지 셑팅하세요
$rss_array = rss_array($channel_list.$channel_query);
// 긁어온 RSS의 채널 태그의 타이틀을 네이버(UTF-8사용) euc-kr로 변환
// 서버 환경이 UTF-8일경우 iconv를 사용하지 않으면 됩니다.
$channel = $rss_array['channel']['title'];
$mt_cha =iconv("utf-8","euc-kr","$channel");
?>
<table width="350" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
} //foreach
echo("</table><p><div align=center></div><br></td></tr></table>");
} // 검색된 뉴스 갯수 IF
else {
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table><br></td></tr></table>");
}
?>
댓글 전체
제가 만든 스킨을 이용해서 최신글 뽑으시려는것 같네요.
foreach문에 if문 하나 달아서 급조해서 바꿔봤습니다. 작동은 잘되구요.
foreach문 시작전부터 foreach문 마지막을 아래처럼 고쳐보세요.
<?
$Ynum = 0;
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
}
$Ynum++;
} //foreach
foreach문에 if문 하나 달아서 급조해서 바꿔봤습니다. 작동은 잘되구요.
foreach문 시작전부터 foreach문 마지막을 아래처럼 고쳐보세요.
<?
$Ynum = 0;
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
}
$Ynum++;
} //foreach
와 넙순님이 직접 답을 주셨네요~~ 감사합니다.
그리고 질문 하는데 급급해서 원본소스표기를 못했습니다. 너그러운 자비를~~
원문 http://www.sir.co.kr/bbs/tb.php/g4_skin/50520/c695fedb53526b0a429fbdaa06ab3c67
시도해보고겠습니다.
그리고 질문 하는데 급급해서 원본소스표기를 못했습니다. 너그러운 자비를~~
원문 http://www.sir.co.kr/bbs/tb.php/g4_skin/50520/c695fedb53526b0a429fbdaa06ab3c67
시도해보고겠습니다.
넙순님 저는 왜 안될까요? 이렇게 써보았습니다.
$Ynum = 0; 부분을 $Ynum = 5; 이렇게 해도 안되네요.. 도와 주세요^^
<?php
include_once("./_common.php");
$html_title = "RSS Reader : 네이버(www.naver.com)";
$g4[title] = "" . $html_title;
// 헤더화일 불러오기(상단메뉴와 왼쪽메뉴가 이곳에서 불러오겠죠)
include_once("./_head.php");
// rss library 불러오기 (그누보드 lib 디렉토리 화일에 rss.lib.php를 저장해두셔야합니다.)
include_once("../lib/rss.lib.php");
// 회원외 접근금지 기능을 사용하시려면 주석을 제거하세요.
//if (!$member[mb_id]) {
// alert("회원이시라면 로그인 후 이용해 보십시오.", "./bbs/login.php");
// }
?>
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td style='padding:10px; line-height:150%;'><b>RSS Reader : 네이버(www.naver.com) 실시간 뉴스 검색</b><br><span class=small> · 방금 퍼온 따끈 따끈한 뉴~스<br/></span></td>
</tr>
</table>
<!-- 공백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>
<!-- 검색 시작 -->
<form name=fnew method=get style="margin:0px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height=30>
<b> 네이버(www.naver.com) 뉴스검색 : </b>
<input type=text id='channel_query' name='channel_query' value=''>
<input type=submit value='검색'>
</td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<?
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 네이버 뉴스 검색 RSS 주소입니다.
$channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
// 기본 검색어를 지정합니다. (각자 상황에 맞게) 예를 들어서 요즘 뜨고 있는 주식시장 코스피로 했습니다.
if($channel_query == '') {
$channel_query = "코스피";
}
// 설정한 채널에서 검색된 뉴스를 읽어온다.
$rss_array = rss_array($channel_list.$channel_query);
// 긁어온 RSS의 채널 태그의 타이틀을 네이버(UTF-8사용) euc-kr로 변환
// 서버 환경이 UTF-8일경우 iconv를 사용하지 않으면 됩니다.
$channel = $rss_array['channel']['title'];
$mt_cha =iconv("utf-8","euc-kr","$channel");
?>
<table width="710" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=3 height=2 bgcolor=#B0ADF5></td></tr>
<tr bgcolor=#F8F8F9 height=30 align=center>
<td width=450><b><?=$mt_cha?></b> 검색 기사(RSS)</td>
<td width=160>신문사(카테고리)</td>
<td width=100>시간</td>
</tr>
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
$Ynum = 0;
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
}
$Ynum++;
//foreach
echo("</table><p><div align=center>위 내용은 RSS를 지원하는 사이트에서 방금 읽어온 내용으로만 구성되어 있습니다.</div><br></td></tr></table>");
} // 검색된 뉴스 갯수 IF
else {
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table><br></td></tr></table>");
}
include_once("./_tail.php");
?>
$Ynum = 0; 부분을 $Ynum = 5; 이렇게 해도 안되네요.. 도와 주세요^^
<?php
include_once("./_common.php");
$html_title = "RSS Reader : 네이버(www.naver.com)";
$g4[title] = "" . $html_title;
// 헤더화일 불러오기(상단메뉴와 왼쪽메뉴가 이곳에서 불러오겠죠)
include_once("./_head.php");
// rss library 불러오기 (그누보드 lib 디렉토리 화일에 rss.lib.php를 저장해두셔야합니다.)
include_once("../lib/rss.lib.php");
// 회원외 접근금지 기능을 사용하시려면 주석을 제거하세요.
//if (!$member[mb_id]) {
// alert("회원이시라면 로그인 후 이용해 보십시오.", "./bbs/login.php");
// }
?>
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td style='padding:10px; line-height:150%;'><b>RSS Reader : 네이버(www.naver.com) 실시간 뉴스 검색</b><br><span class=small> · 방금 퍼온 따끈 따끈한 뉴~스<br/></span></td>
</tr>
</table>
<!-- 공백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>
<!-- 검색 시작 -->
<form name=fnew method=get style="margin:0px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height=30>
<b> 네이버(www.naver.com) 뉴스검색 : </b>
<input type=text id='channel_query' name='channel_query' value=''>
<input type=submit value='검색'>
</td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<?
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 네이버 뉴스 검색 RSS 주소입니다.
$channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
// 기본 검색어를 지정합니다. (각자 상황에 맞게) 예를 들어서 요즘 뜨고 있는 주식시장 코스피로 했습니다.
if($channel_query == '') {
$channel_query = "코스피";
}
// 설정한 채널에서 검색된 뉴스를 읽어온다.
$rss_array = rss_array($channel_list.$channel_query);
// 긁어온 RSS의 채널 태그의 타이틀을 네이버(UTF-8사용) euc-kr로 변환
// 서버 환경이 UTF-8일경우 iconv를 사용하지 않으면 됩니다.
$channel = $rss_array['channel']['title'];
$mt_cha =iconv("utf-8","euc-kr","$channel");
?>
<table width="710" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=3 height=2 bgcolor=#B0ADF5></td></tr>
<tr bgcolor=#F8F8F9 height=30 align=center>
<td width=450><b><?=$mt_cha?></b> 검색 기사(RSS)</td>
<td width=160>신문사(카테고리)</td>
<td width=100>시간</td>
</tr>
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
$Ynum = 0;
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['author']}");
$category = iconv("utf-8","euc-kr","{$item['category']}");
$url = $item['link'];
$pubdate = date('Y-m-d H:i:s', strtotime($item['pubdate']));
$arr_date = substr($pubdate, 2,2)."-".substr($pubdate, 5,2)."-".substr($pubdate, 8,2)." ".substr($pubdate, 11,8);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='20' style='padding-left:10px;' width=350><a href='<?=$url?>' target='_blank'><?=$mtt1?></a></td></tr>
<tr><td colspan='3' height=1 bgcolor="#E1DFD0"></td></tr>
<?
}
$Ynum++;
//foreach
echo("</table><p><div align=center>위 내용은 RSS를 지원하는 사이트에서 방금 읽어온 내용으로만 구성되어 있습니다.</div><br></td></tr></table>");
} // 검색된 뉴스 갯수 IF
else {
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table><br></td></tr></table>");
}
include_once("./_tail.php");
?>
죄송합니다. 답변 올리면서 소스를 잘못올렸네요.
foreach ($rss_array['items'] as $item) {
밑 부분에 이렇게
if( $Ynum < 5) {
한줄만 추가해보세요..
foreach ($rss_array['items'] as $item) {
밑 부분에 이렇게
if( $Ynum < 5) {
한줄만 추가해보세요..
$Ynum = 0;
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
if( $Ynum < 5) {
.
.
.
.
.
.
$Ynum++;
이렇게만 들어가면 되나요? 저는 잘안되네요. 넙순님 다시한번 가르침 부탁드리겠습니다.
if(count($rss_array['items']) > 0 ) {
foreach ($rss_array['items'] as $item) {
if( $Ynum < 5) {
.
.
.
.
.
.
$Ynum++;
이렇게만 들어가면 되나요? 저는 잘안되네요. 넙순님 다시한번 가르침 부탁드리겠습니다.