How to add category(posts) in wordpress single post


Hey any one know how to add a specific category posts in wordpress single post.m giving a link of website that is using it <a href="http://www.animetv.org/anime/one-piece-dub/" rel="nofollow">http://www.animetv.org/anime/one-piece-dub/</a> it is a post that contains posts of a particular category.It is demanded as same i.e. with post thumbnails.Thanks.


Just put this code at your single.php file you will get your desired result:

<?php $category = get_the_category(); ?> <ul> <?php $args = array('category' => $category[0]->term_id ); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail();?></a><br/> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; wp_reset_postdata();?> </ul>

And put css for ul li as per your choice like li{float : left;}


If you want to display the posts from a specific category in single.php page, please add the following code to the the file.

<?php $posts = new WP_Query(); $posts->query( "category_name='{enter your category slug here}'&posts_per_page={enter the number of posts to display here}" ); if($posts->have_posts()) : while ($posts->have_posts()) : $posts->the_post(); ?> <div> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> </div> <div> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </div> <?php endwhile; endif; wp_reset_postdata(); ?>


  • how to for loop a variable inside an R functon
  • xmllint : validate an XML file against two XSD schemas (envelope / payload)
  • Gridview image gallery from binary data images
  • ffmpeg - multiple output with thumbnails
  • How to find origID for getThumbnail when taking a picture with camera.TakePicture
  • Expand the functionality of wpf
  • Copying different structs to byte arrays
  • C++ cout and enum representations
  • Java: can you cast Class into a specific interface?
  • AES padding and writing the ciphertext to a disk file
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • Jquery - Jquery Wysiwyg return html as a string
  • Matplotlib draw Spline from multiple points
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • A cron job substitute?
  • json Serialization in asp
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • Trying to get generic when generic is not available
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • How can I remove ASP.NET Designer.cs files?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal