List current category post with thumbnails and pagination
-
I’m trying to make a list of posts from the current category (“Other posts from the same category”). In my list I would like to have:
START LINK
-THUMBNAIL IMAGE
-TITLE
END LINKI would also like to have a pagination at the end if the related posts are many.
I found something who helped me to list the posts, but I don’t get the thumbnail to work. I’m also trying to figure out how to add the pagination.
<?php //Gets category and author info global $wp_query; $cats = get_the_category(); $tempQuery = $wp_query; $currentId = $post->ID; // related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "posts_per_page=5&cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count = 0; if (have_posts()) { while (have_posts()) { the_post(); if( $count<4 && $currentId!=$post->ID) { $count++; $categoryPosts .= '<li><a href="' . get_permalink() . '">' . get_the_post_thumbnail( "ID", "thumbnail" ) . '</a><br /><a href="' . get_permalink() . '">' . the_title( "", "", false ) . '</a></li>'; } } } $wp_query = $tempQuery; ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <h2>Detta ?r kategori: <?php the_category(', ');?></h2> <ul> <?php echo $categoryPosts; ?> </ul> <?php endwhile;?>
Very greatful for all the help I can get. Thanks in advance!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘List current category post with thumbnails and pagination’ is closed to new replies.