2013-03-10 4 views
0

저는 현재 사용자 정의 Wordpress 테마를 개발하려고하고 있습니다. 내 홈페이지에서 두 번째 콘텐츠 블록을 추가해야합니다. 나는이 작업을 수행하기 위해 플러그인을 사용하고 있는데, 콘텐츠 블록을 원하는 곳에 다음을 추가하면됩니다.WordPress PHP 루프 계속하기

<?php the_block('Latest Products')?> 

그러나이 내용을 추가하면 효과가없는 것 같아요. 내 PHP의 형식 때문입니다. 나는 PHP에 상당히 익숙하다. 그래서 어떤 도움이라도 대단히 감사한다.

내 코드는 다음과 같습니다. - 나는 HTML의 가장 좋은 부분을 잘라 냈습니다. 나는 그것이 'endforeach'태그와 관련이 있다고 생각하니?

<?php get_header(); ?> 

<?php if(have_posts()) :?> 
<?php while (have_posts()) : the_post(); ?> 

<?php the_content(); ?> 

<?php 
global $post; 
$myposts = get_posts('numberposts=4&category=1'); 
foreach($myposts as $post) : 
?>      
<div class="blogsnippet"> 
<div class="postdate"> 
    <span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php the_time('M');?></span> 
</div> 
<div class="postexcerpt"> 
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3> 
<p><?php echo(get_the_excerpt());?></p> 
</div> 
</div> 

<?php endforeach;?>    

<?php the_block('Latest Products')?> 

<?php endwhile; endif; ?> 

<?php get_footer(); ?> 

편집

좋아, 그래서 분명히, 그러나 그것은 여전히 ​​작동하지 않습니다, 루프 외부에 넣어해야합니다. 어떤 아이디어?

<?php get_header(); ?> 

<?php if(have_posts()) :?> 
<?php while (have_posts()) : the_post(); ?> 

<?php the_content(); ?> 

<?php 
global $post; 
$myposts = get_posts('numberposts=4&category=1'); 
foreach($myposts as $post) : 
?>      
<div class="blogsnippet"> 
<div class="postdate"> 
<span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php  the_time('M');?></span> 
</div> 
<div class="postexcerpt"> 
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3> 
<p><?php echo(get_the_excerpt());?></p> 
</div> 
</div> 

<?php endforeach;?>    
<?php endwhile; endif; ?> 

<?php the_block('Latest Products')?> 

<?php get_footer(); ?> 

답변

1

이것은 주로 코드 구문이 올바르므로 플러그인이 실제로 수행하는 작업에 따라 다릅니다.

Multiple Content Blocks 플러그인을 사용하고 있고 최신 Wordpress 버전 3.5.1을 사용중인 경우 플러그인이 호환되지 않을 수 있다고 생각합니다. 이 문제가 될 수 있기 때문에 귀하의 Wordpress에 플러그인의 버전 호환성을 확인하겠습니다.

편집 :

플러그인은() 함수 the_content에 필터를 적용하여 작동 그래서 그것은 단지라고 the_content() 함수 전에 the_block()를 선언하여 작동하는 이유입니다.

해결책은 출력 the_block을 (캡처) 및 예를 들어, 나중에 인쇄 사용할 수 :

<?php 
    ob_start(); 
    the_block('Latest Products'); 
    $latest_products_contents = ob_get_contents(); 
    ob_end_clean(); 
?> 
<!-- Further down.. --> 
<?php echo $latest_products_contents; ?> 
+0

감사 라이언 - 아직 호환성의 결정에 충분한 데이터가 아니다 - 한 사람이 작동 말한다 하지만 그게 전부입니다. 웬일인지 페이지 편집기에서 두 번째 편집 가능 영역이 루프 외부에있는 동안 표시되지 않습니다. 루프 안쪽에 넣으면, 특히 최신 4 개의 게시물을 호출하는 섹션 위에 표시되고 루프 내에서도 잘 작동하지만 분명히 그 아래에 필요합니다. 이것은 내가 그 코드로 무언가가 잘못되었다고 생각하게하지만, 나는 말할 수있을만큼 충분히 경험이 없다. –

+0

문제를 해결할 내 대답을 편집했습니다. 코드가 정확합니다. 특정 순서가 필요한 플러그인 일뿐입니다. –