Put this in your sidebar template where you want the listing to show up. Alternatively, you could use a plugin that allows you to run php in widgets and then place directly in a widget box, but that’s not always wise.
<?php
$categories = get_the_category();
$category = $categories[0];
$category_id = $category->cat_ID;
$args = array('category__in' => $category_id, 'posts_per_page' => '5');
$recent_in_cat = new WP_Query( $args );if ( $recent_in_cat->have_posts() ) {while ( $recent_in_cat->have_posts() ) {$recent_in_cat->the_post();
?>
<p><a href="https://wordpress.stackexchange.com/questions/192761/<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<? php
}} wp_reset_postdata();
?>
Note that the start and end tags <?php
and ?>
should only be there unless you’re already in the middle of (unclosed) php code, else skip them.
Related Posts:
- Custom text box containing post titles
- Display recent posts with thumbnail within Masonry
- How do I use wp_get_recent_posts?
- Add Date to Recent Posts Widget?
- Recent Posts widget has some older posts at the top? [closed]
- how to show post content with post name in sidebar?
- Adding a badge to new blog post titles
- How to make slider show 4 recent news and news start from begining not from 4th
- Display recent post by tag
- Small intro before latest blog posts
- WordPress Recent post only showing title
- Recent post on single page from specyfic category
- How to display posts on template
- Get Each user recent post in wordpress
- How to display last 3 posts (recent posts) in a static page?
- Code for Recent Posts Widget
- Display list of most used tags in the last 30 days
- Modify recent post sidebar to show post thumbs with out plugins
- Querying post from a multisite network
- Add inline HTML to posts published within last 24hrs
- Modifying recent post widget to include icons for post titles
- Related Posts loop – offset
- Show one post per author and limit query to 8 posts
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Empty excerpt using wp_get_recent_posts
- Display Custom Post Type in Recent Posts
- Show recent published posts
- How to hide a post from ‘Recent Posts’ widget?
- customizing recent posts
- Display the date before the post title in recent posts widget
- How to display recent posts added in several custom post types
- How to display recent / random posts by its category
- Grabbing specific content
- How to get most recent commented post above new submitted post in WordPress?
- Two posts are loaded instead of one?
- Recent Posts widget without Title
- How to start with post number x?
- Use wp_get_recent_posts with search term
- Create static front-page with 3-5 recent posts
- the_excerpt not showing posts
- How to truncate titles in Recent Posts widget?
- Recent posts with featured image or fallback image with permalink
- recent posts for different categories
- Excluding a category from wp_query breaks recent post widget
- How do I add recent posts to the menu?
- How do I exclude recent post from recent post php widget
- How to output only blockquotes content from recent posts in a widget?
- menu item to display the most recent post
- Single-post preview repeats thumbnails in Jupiter Recent Posts widget
- Custom recent-posts shortcode’s thumbnail image not in line with rest of code
- How to get date of post when using wp_get_recent_posts()?
- Proper way to display latest 5 posts grouped by post type?
- Reset WordPress Post Query to default
- link to single most recent post, regardless of category
- Most recent post is missing from Author page
- How to check if the current page is at a specified path in the URL?
- ‘Recent Posts’ links open in new window, without copying the ‘WP_Widget_Recent_Posts’ class
- Latest posts by category — how to exclude current post?
- Show recent posts starting at a specific number archive
- How do I get the content excerpt of the recent post?
- Recent posts on homepage: different thumbnail based on logged in status and post category
- How to Link to Most Recent Custom Post of Same Term
- widget_posts_args not using the number of posts in widget
- 2 column recent post query not respecting float right [closed]
- Sort / display recent posts by publish date
- Exclude latest post from WP_Query taxonomy term loop
- List recent posts with link to first category
- Display recent posts on another site
- Why aren’t paragraphs breaking on this page?
- Get x recent posts by author?
- Showing recent post of category in page
- How to show 3 most recent/viewed posts in a special tiles on home page using wordpress?
- Manual excerpt length on recent posts slider
- How to add a recent post function to a text widget I created for practice?
- Offset Loop by 1 , Limit next loop to 1 (Most Recent) Post
- Show latest posts on responsive theme
- showing all recent posts in theme
- post preview/thumbnails not displaying correctly- linking to “home” instead of post?
- How do I add a small excerpt of a blog post on my Front Page Recent Posts widget?
- Editing HTML structure of Gutenberg layout recent post?
- Linking to the most recent post in my podcast category
- WordPress recent post
- Posts Per Page with a button to add more Posts
- Is it possible to show thumbnails along with recent post from a wordpress blog on static website’s homepage?
- date_query problem
- Recent post in the middle of the content
- Recent posts show thumbnail
- Autoblog posts in wpms(network) into main site including featured images
- Paginate recent posts widget
- Have latest post and recent posts display differently
- Show recent posts in single-post page
- Duplicate content with the same URL, google authorship
- shortcode for recent custom type post
- Query recent posts by author
- Adjust layout most recent post, taking pagination into account
- Author Link in Recent Posts Widget
- Lists Top Authors by Most Recent Posts
- How to display recent posts on home page with title, post date, author and featured image?
- How to filter content by language with WPGlobus
- How to display Most Recently Read 10 Posts by a logged in user in wordpress