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

    I 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)
  • Thread Starter Linosa

    (@linosa)

    So I solved the thumbnail part. Still need help with the pagination though!

    Thread Starter Linosa

    (@linosa)

    I solved it myself.

    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>
    
    <ul>
    <?php
    	global $post;
    	$categories = get_the_category();
    	$thiscat = $categories[0]->cat_ID;
    ?>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'posts_per_page' => 4,
      'paged' => $paged,
      'cat' => $thiscat
    );
    
    query_posts($args);
    ?>
    
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail("thumbnail"); ?><br />
    	<?php the_title(); ?>	</a></li>						
    
    	<?php endwhile; ?>
    
    	<?php html5wp_pagination(); ?>
    
      	<?php endif; ?>
    
    <?php wp_reset_query(); ?>
     </ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List current category post with thumbnails and pagination’ is closed to new replies.