2012-06-26 2 views
1

나는 'list-two'(Advanced Custom Fields 사용)라는 사용자 정의 메타 상자가 있는데 편집 창에서 'more'태그를 사용하여 텍스트/내용을 두 개로 나누고 싶습니다. 열. 이것은 지금까지 내 코드 만 내가 필요의 절반이 할을 수행합니다두 개의 열로 내용 나누기 - Wordpress

<?php 
// split text into array 
    $copy = split_morecontent(); 
// output first content section in column1 
echo '<section class="split">', array_shift($copy), '</section>'; 
// output remaining content sections in column2 
echo '<section class="split">', implode($copy), '</section>'; 
?> 

출력 : 내 게시물 템플릿 파일에서

function split_morecontent() { 
global $morecontent; 
$morecontent = true; 
$copy = preg_split('/<span id="more-\d+"><\/span>/i', get_field('list_two')); 
for($c = 0, $csize = count($copy); $c < $csize; $c++) { 
    $copy[$c] = apply_filters('list_two', $copy[$c]); 
} 
return $copy; 
} 

: 내 functions.php 파일에서

다음 HTML을 실행하면 (실제로 두 태그로 콘텐츠가 분할되지 않음을 알 수 있습니다) :

<section class="split"> 
    <ul class="footnote"> 
    <li>Christopher Gray</li> 
    <li>Jean Jullien<!--more--></li> 
    <li>Nous Vous</li> 
    <li>Liv Bargman</li> 
    <li>Luke Drozd</li> 
    </ul> 
</section> 

<section class="split"> 
    <!-- the last 3 <li> tags from the list above should be displayed within here.--> 
</section> 

답변

1

당신을 도울지도 모르는 것처럼 보이는 SitePoint에서의 ticle. Check out How to Split WordPress Content Into Two or More Columns.

당신의 functions.php에 추가 :

// split content at the more tag and return an array 
function split_content() { 
    global $more; 
    $more = true; 
    $content = preg_split('/<span id="more-\d+"><\/span>/i', get_the_content('more')); 
    for($c = 0, $csize = count($content); $c < $csize; $c++) { 
     $content[$c] = apply_filters('the_content', $content[$c]); 
    } 
    return $content; 
} 

을이 부문은 교체해야합니다 (I 대부분의 테마에 대해 기본적으로 single.php을 가정하고)이 발생하여 원하는 목적지 기본적으로, 다음을 수행 할 것을 새로과 같이, split_content() 생성과 the_content() 전화 :

<?php 
    // original content display 
     // the_content(); 
    // split content into array 
     $content = split_content(); 
    // output first content section in column1 
     echo '<div id="column1">', array_shift($content), '</div>'; 
    // output remaining content sections in column2 
     echo '<div id="column2">', implode($content), '</div>'; 
?> 

는 이제 두 개의 분리 된 div에 내용 분할이있다. 각 너비에 그들에게 float을 적용하면 <!--more--> 태그를 사용하여 내용을 두 개의 열로 구분할 수 있습니다.

+0

내가 편집하려고하는 코드가 맞다. 기본적으로 Sitepoint의 코드는 the_content 만 분리합니다. 나는 다른 WYSIWYG 콘텐츠 상자 (나는 list_two를 호출했다)를 분할하기 위해 그것을 적용하려고 노력하고 있지만 작동시키지 못한다. 따라서 Post 편집 페이지에서 추가 WYSIWYG 편집기로 작업하려면 SitePoint 코드가 필요합니다. 내가 어떻게 그럴 수 있니? – egr103

1

또 다른 쉬운 방법은 jQuery를 사용하는 것입니다. 그것은 아주 간단합니다. 사용이 : Columnizer jQuery Plugin

그것을 이런 식으로 뭔가를 작동합니다

$('.post-content').columnize({ columns: 2 }); 

그리고 루프 그냥 다른 사람을 위해 도움이 사업부 포스트 내용

<div class="post-content"> 
    <?php the_content() ?> 
</div> 

희망 내부 the_content()를 대신에

;)

관련 문제