스택의 멋진 사람들, 다시 한 번 도움을 요청합니다.WordPress blog_content 글자 수 제한
나는 현재 예를 들어, 워드 프레스 설치를 포함하는 하위 폴더에서 블로그 콘텐츠를 끌어 외부 웹 사이트가 :
웹 사이트 A : 외부 정적 웹 사이트 웹 사이트 B : 내가 가진
워드 프레스 설치 게시물은 다음 코드를 사용하여 웹 사이트 A의 홈페이지에 포함됩니다.
워드 프레스 콜 :
이 블로그 게시물에 포함<?php
//db parameters
$db_username = '###';
$db_password = '###';
$db_database = '###';
$blog_url = 'http://www.website.com/blog/';
//connect to the database
mysql_connect('###', $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");
//get data from database -- !IMPORTANT, the "LIMIT 5" means how many posts will appear. Change the 5 to any whole number.
$query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 1";
$query_result = mysql_query($query);
$num_rows = mysql_numrows($query_result);
//close database connection
mysql_close();
// html page starts after
?>
: 이것은 완벽하게 작동
<div class="contentBox">
<?php
for($i=0; $i< $num_rows; $i++){
//assign data to variables, $i is the row number, which increases with each run of the loop
$blog_date = mysql_result($query_result, $i, "post_date");
$blog_title = mysql_result($query_result, $i, "post_title");
$blog_content = mysql_result($query_result, $i, "post_content");
//$blog_permalink = mysql_result($query_result, $i, "guid"); //use this line for p=11 format.
$blog_permalink = $blog_url . mysql_result($query_result, $i, "post_name"); //combine blog url, with permalink title. Use this for title format
//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);
//the following HTML content will be generated on the page as many times as the loop runs. In this case 5.
?>
<div class="post"></div>
<img src="img/headers/news-from.png" /><br />
<p class="blogName"><a href="http://www.website.com/blog"><?php echo $blog_title; ?></a></p>
<p style="margin-top: -10px; margin-right: 10px;"><?php echo $blog_content;?></p>
<p>Submitted on: <span class="green"><?php echo $blog_date; ?></span></p>
<p><a href=”<?php echo $blog_permalink; ?>”>Read Full Post</a></p>
<?php
} //end the for loop
?>
</div>
, 그것은 필요한 게시물을 끌어와 표시합니다, 내가 가진 모든 멋지고 형식 등 문제가 있다는 것입니다 나는 실제로 잡아 당기는 문자 수를 제한 할 필요가있다. 현재 서체의 전체 메아리는 반향이며, 게시물의 처음 15 문자 만 반향시켜야한다. 어떤 아이디어라도 대단히 감사하겠습니다.
작동하지 않습니까? 게시물 내용 대신 문단에 1을 게시하는 것이 두려운가요? –
내 업데이트 된 게시물을 참조하십시오. – MikeF
편집 후 다시 테스트 됨 : 완벽하게 작동했습니다! 고마워요! –