2016-07-11 3 views
0

나는 내 wordpress 사이트에 30 개의 게시물을 가지고 있습니다. 그리고 페이지에 4 개의 게시물을 표시했습니다. 어떻게 번호 매기기를 추가 할 수 있습니까?워드 프레스에서 게시물 번호 매기기를 추가하는 방법

<div class="eventssec hidden-xs hidden-sm"> 
<?php 
$type = 'posts'; 
$args=array(
'post_type' => $type, 
'posts_per_page'=>4, 
'caller_get_posts'=>1, 
'order'=>'asc' 
); 
$my_query = new WP_Query($args); 
$i=0; 
while ($my_query->have_posts()) : $my_query->the_post(); ?> 
<div class="events"> 
<figure> 
<?php 
$image = get_field('image'); 
if(!empty($image)): ?> 
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> 
<?php endif; ?> 
</figure> 
<div class="desctext"> 
<h2><?php the_field('name'); ?></h2> 
<p><?php the_field('designition'); ?></p> 
<p><?php the_field('emp-id'); ?></p> 
</div> 
</div> 
<?php $i++; endwhile; wp_reset_query(); ?> 
</div> 

답변

2

이 오류를 얻기이

<div class="eventssec hidden-xs hidden-sm"> 
    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $type = 'posts'; 
    $args=array(
    'post_type' => $type, 
    'posts_per_page'=>4, 
    'caller_get_posts'=>1, 
    'paged' => $paged, 
    'order'=>'asc' 
    ); 
    $my_query = new WP_Query($args); 
    $i=0; 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
    <div class="events"> 
    <figure> 
    <?php 
    $image = get_field('image'); 
    if(!empty($image)): ?> 
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> 
    <?php endif; ?> 
    </figure> 
    <div class="desctext"> 
    <h2><?php the_field('name'); ?></h2> 
    <p><?php the_field('designition'); ?></p> 
    <p><?php the_field('emp-id'); ?></p> 
    </div> 
    </div> 
    <?php $i++; endwhile; 
    my_custom_pagination($my_query->max_num_pages, "", $paged); 
    wp_reset_query(); ?> 
    </div> 

    <?php 
    function my_custom_pagination($numpages = '', $pagerange = '', $paged = '', $search = false) { 

    if (empty($pagerange)) { 
     $pagerange = 2; 
    } 

    /** 
    * This first part of our function is a fallback 
    * for custom pagination inside a regular loop that 
    * uses the global $paged and global $wp_query variables. 
    * 
    * It's good because we can now override default pagination 
    * in our theme, and use this function in default queries 
    * and custom queries. 
    */ 
    global $paged; 
    if (empty($paged)) { 
     $paged = 1; 
    } 
    if ($numpages == '') { 
     global $wp_query; 
     $numpages = $wp_query->max_num_pages; 
     if (!$numpages) { 
      $numpages = 1; 
     } 
    } 

    if ($search) { 
     $format = '&paged=%#%'; 
    } else { 
     $format = 'page/%#%'; 
    } 
    /** 
    * We construct the pagination arguments to enter into our paginate_links 
    * function. 
    */ 
    $pagination_args = array(
     'base' => get_pagenum_link(1) . '%_%', 
     'format' => $format, 
     // 'format' => '&paged=%#%', 
     'total' => $numpages, 
     'current' => $paged, 
     'show_all' => False, 
     'end_size' => 1, 
     'mid_size' => $pagerange, 
     'prev_next' => True, 
     'prev_text' => __('&laquo;'), 
     'next_text' => __('&raquo;'), 
     'type' => 'plain', 
     'add_args' => false, 
     'add_fragment' => '' 
    ); 

    $paginate_links = paginate_links($pagination_args); 

    if ($paginate_links) { 
     echo "<nav class='custom-pagination'>"; 
     //echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> "; 
     echo $paginate_links; 
     echo "</nav>"; 
    } 
    } 
+0

을 시도해보십시오

여기 내 코드입니다. 치명적인 오류 : D : \ xampp \ htdocs \ velma \ wp-content \ themes \ velma \ page-templates \ sub_committee.php의 88 행에있는 정의되지 않은 함수 my_custom_pagination()을 호출하십시오. –

+0

여기에서 my_custom_pagination 함수를 잘라내어 function.php 내가 마지막에 정의한 –

+0

굉장! 작동 중! 감사 –

관련 문제