2014-09-17 4 views
0

사용자 정의 페이지 템플릿으로 가져온 카테고리에서 게시물의 발췌 내용을 표시하려고합니다.카테고리 "게시물"에 게시물 크기를 제한하려고합니다.

페이지에 삽입 된 모든 카테고리 게시물이 전체 게시물을 표시합니다. 나는 대략 40 단어 (또는 x 문자 수)를 보여주고 "더 읽기 >>"발췌를 보여주고 싶다.

또한 페이지에 표시된 글의 수를 대략 5 개 이하로 최대한 늘리고 싶습니다.

<?php while (have_posts()) : the_post(); ?> 
<?php get_template_part('content', 'page'); ?> 

<?php 
$catPost = get_posts('cat=225&posts_per_page=3'); 
foreach ($catPost as $post) : setup_postdata($post); 
?> 

<?php get_template_part('content'); ?> 
<?php endforeach;?> 
<?php comments_template('', true); ?> 
<?php endwhile; // end of the loop. ?> 
+0

당신이하고 싶다는 것이 좋습니다! 너 왜 여기 있니? – Xatenev

+0

시도한 것에 대해 이야기 해보십시오. 그래서 모든 코드를 제공하지는 않습니다. – drmarvelous

답변

0

를 표시 할 문자의 수는 다음과 같은 코드에 의해 콘텐츠를 템플릿에 the_content()를 교체입니다

function new_excerpt_length($length) { 
    return 40; 
} 
add_filter('excerpt_length', 'new_excerpt_length'); 

이 추가

$content = get_the_content(); 
    $trimmed_content = wp_trim_words($content, 40, '<a href="'. get_permalink() .'"> ...' . Read More . '</a>'); 
    echo trimmed_content; 

또는에 다음 코드를 사용할 수 있습니다.파일

function excerpt($num) { 
    $limit = $num+1; 
    $excerpt = explode(' ', get_the_excerpt(), $limit); 
    array_pop($excerpt); 
    $excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read More</a>"; 
    echo $excerpt; 
    } 

function excerpt_length($length) { 
    return 40; 
} 
add_filter('excerpt_length', 'excerpt_length'); 

이제 콘텐츠를 템플릿에 the_excerpt()에 의해 the_content()를 교체합니다.

+0

감사합니다. Bir - 두 번째 제안은 티켓입니다. 감사합니다! – Visitor14

0

당신의 function.php 파일이 40 당신이

관련 문제