Skip to content

Instantly share code, notes, and snippets.

@amrinz
Last active April 7, 2020 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrinz/4bbae9dd80f5ed03973b734b5090b189 to your computer and use it in GitHub Desktop.
Save amrinz/4bbae9dd80f5ed03973b734b5090b189 to your computer and use it in GitHub Desktop.
Displays current logged in user posts in table
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$postcount = 10;
$wp_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => $postcount,
'author' => get_current_user_id(),
'paged' => $paged
) );
?>
<?php if ( $wp_query->have_posts() ): ?>
<div class="table-responsive">
<table class="table table-striped table-borderless">
<tr><th>No</th><th>Judul</td><th>Kategori</th><th>Lokasi</th></tr>
<?php $i = 0; while ( $wp_query->have_posts()): $wp_query->the_post(); $i++; ?>
<tr>
<td><?php if($paged >= 2) { echo (($paged*$postcount)-$postcount)+$i; } else { echo $i; } ?></td>
<td><a href="<?php the_permalink(); ?>" title="<?php _e('Continue reading', 'lombokmedia'); ?> <?php the_title(); ?>"><?php the_title(); ?></a></td>
<td><?php the_category( ' ' ); ?></td>
<td><?php echo get_the_term_list( get_the_ID(), 'lokasi', '', ', ', '' ); ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
<?php lmd_page_navi(); //my-custom page navigation
wp_reset_postdata(); ?>
<?php else:
get_template_part('lmd-nothing'); //template to display message no post found
endif; ?>
@amrinz
Copy link
Author

amrinz commented Apr 7, 2020

For those who can't find how to display post numbering in table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment