2016-07-11 3 views
0

Ich habe 30 Beiträge in meiner Wordpress-Website. Und zeigte 4 Posts auf der Seite an. Wie kann ich nummerierte Paginierung hinzufügen?Wie Nummer Seitenumbruch für Beiträge in WordPress hinzufügen

Hier ist mein Code:

<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> 

Antwort

2

dieses Versuchen

<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

diesen Fehler. Schwerwiegender Fehler: Aufruf von undefined Funktion my_custom_pagination() in D: \ xampp \ htdocs \ velma \ wp-content \ themes \ velma \ page-templates \ sub_committee.php in Zeile 88 –

+0

Bitte schneiden Sie my_custom_pagination Funktion von hier und legen Sie es in Ihrem function.php , die ich in der letzten –

+0

definieren Super! Es funktioniert!! Vielen Dank –

Verwandte Themen