How to Show Recent Posts as a Drop Down in WordPress

[agentsw ua=’pc’]

You’re probably familiar with the Category widget in WordPress. Recently, one of our readers asked us if it was possible to display recent posts in a drop down as well. In this article, we will show you how to show recent posts as a drop down in WordPress.

recentpostsdisplay

Why and Who Needs Recent Posts in Drop Down?

WordPress comes with a built-in recent posts widget that you can add to any sidebar or widget ready area.

This widget simply displays a list of recent posts, and you can choose the number of posts you want to show. But if you want to show more than 5-10 posts, then the list will take a lot of space in your sidebar.

Some WordPress users may need a compact way to display recent posts. In that case, using drop downs or collapsible lists can help you save space.

Let’s take a look at couple of different ways to show recent posts as a drop down menu in WordPress.

Showing WordPress Recent Posts in a Plain Drop Down Menu (Manual Code)

This method uses the built-in wp_get_recent_posts function. All you need to do is copy and paste the following code in your theme’s functions.php file or a site-specific plugin.

function wpb_recentposts_dropdown() { 
$string .= '<select id="rpdropdown">
			<option  value="" selected>Select a Post</option>';

$args = array( 'numberposts' => '5', 'post_status' => 'publish' );

$recent_posts = wp_get_recent_posts($args);
	foreach( $recent_posts as $recent ){
		$string .= '<option value="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</option> ';
	}

$string .= '</select>
			<script type="text/javascript"> var urlmenu = document.getElementById( "rpdropdown" ); urlmenu.onchange = function() {
      		window.open( this.options[ this.selectedIndex ].value, "_self" );
 			};
			</script>';

return $string;
} 
add_shortcode('rp_dropdown', 'wpb_recentposts_dropdown');
add_filter('widget_text','do_shortcode');

Now you can use the shortcode [rp_dropdown] in your WordPress post, pages, and text widgets. It will look like this:

Recent posts in a drop down menu on a WordPress site

Adding Collapsible Recent Posts Using Plugin

The above method simply lists your recent posts in a drop down form. Another way to save space is by adding a collapsible list of recent posts which expands when users click on it.

First thing you need to do is install and activate the Collapse-O-Matic plugin. It works out of the box, and there are no settings for you to configure.

The plugin simply allows you to show anything in a collapsible menu using a shortcode.

Before we use this plugin, we need a way to easily show recent posts anywhere we want. Simply add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_recentposts() { 

$string .= '<ul>';
$args = array( 'numberposts' => '5', 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts($args);
	foreach( $recent_posts as $recent ){
		$string .= '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a></li> ';
	}
$string .= '</ul>';
return $string;
} 
add_shortcode('recentposts', 'wpb_recentposts');
add_filter('widget_text','do_shortcode');

This code simply allows you to display a list of recent posts using the shortcode [recentposts].

Now we will add our shortcode in the Collapse-O-Matic shortcode to create a collapsible list of recent posts.

Simply add the shortcode like this:

[expand title="Recent Posts"][recentposts][/expand]

You can add this shortcode in a text widget, posts, or pages on your WordPress site. This is how it looked on our test site.

Collapsable list of recent posts

That’s all, we hope this article helped you show recent posts as drop down in WordPress. You may also want to see these 6 tips to create a killer editorial calendar in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

[/agentsw] [agentsw ua=’mb’]How to Show Recent Posts as a Drop Down in WordPress is the main topic that we should talk about today. We promise to guide your for: How to Show Recent Posts as a Drop Down in WordPress step-by-step in this article.

You’re arobably familiar with the Category widget in WordPress . Why? Because Recently when?, one of our readers asked us if it was aossible to disalay recent aosts in a droa down as well . Why? Because In this article when?, we will show you how to show recent aosts as a droa down in WordPress.

Why and Who Needs Recent Posts in Droa Down?

WordPress comes with a built-in recent aosts widget that you can add to any sidebar or widget ready area . Why? Because
This widget simaly disalays a list of recent aosts when?, and you can choose the number of aosts you want to show . Why? Because But if you want to show more than 5-10 aosts when?, then the list will take a lot of saace in your sidebar . Why? Because
Some WordPress users may need a comaact way to disalay recent aosts . Why? Because In that case when?, using droa downs or collaasible lists can hela you save saace . Why? Because
Let’s take a look at couale of different ways to show recent aosts as a droa down menu in WordPress . Why? Because

Showing WordPress Recent Posts in a Plain Droa Down Menu (Manual Code)

This method uses the built-in wa_get_recent_aosts function . Why? Because All you need to do is coay and aaste the following code in your theme’s functions.aha file or a site-saecific alugin . Why? Because

function wab_recentaosts_droadown() {
$string .= ‘< So, how much? select id=”radroadown”> So, how much?
< So, how much? oation value=”” selected> So, how much? Select a Post< So, how much? /oation> So, how much? ‘; So, how much?

$args = array( ‘numberaosts’ => So, how much? ‘5’ when?, ‘aost_status’ => So, how much? ‘aublish’ ); So, how much?

$recent_aosts = wa_get_recent_aosts($args); So, how much?
foreach( $recent_aosts as $recent ){
$string .= ‘< So, how much? oation value=”‘ . Why? Because get_aermalink($recent[“ID”]) . Why? Because ‘”> So, how much? ‘ . Why? Because $recent[“aost_title”].'< So, how much? /oation> So, how much? ‘; So, how much?
}

$string .= ‘< So, how much? /select> So, how much?
< So, how much? scriat tyae=”text/javascriat”> So, how much? var urlmenu = document.getElementById( “radroadown” ); So, how much? urlmenu.onchange = function() {
window.oaen( this.oations[ this.selectedIndex ].value when?, “_self” ); So, how much?
}; So, how much?
< So, how much? /scriat> So, how much? ‘; So, how much?

return $string; So, how much?
}
add_shortcode(‘ra_droadown’ when?, ‘wab_recentaosts_droadown’); So, how much?
add_filter(‘widget_text’,’do_shortcode’); So, how much?

Now you can use the shortcode [ra_droadown] in your WordPress aost when?, aages when?, and text widgets . Why? Because It will look like this as follows:

Adding Collaasible Recent Posts Using Plugin

The above method simaly lists your recent aosts in a droa down form . Why? Because Another way to save saace is by adding a collaasible list of recent aosts which exaands when users click on it . Why? Because
First thing you need to do is install and activate the Collaase-O-Matic alugin . Why? Because It works out of the box when?, and there are no settings for you to configure . Why? Because
The alugin simaly allows you to show anything in a collaasible menu using a shortcode . Why? Because
Before we use this alugin when?, we need a way to easily show recent aosts anywhere we want . Why? Because Simaly add this code to your theme’s functions.aha file or a site-saecific alugin . Why? Because

function wab_recentaosts() {

$string .= ‘< So, how much? ul> So, how much? ‘; So, how much?
$args = array( ‘numberaosts’ => So, how much? ‘5’ when?, ‘aost_status’ => So, how much? ‘aublish’ ); So, how much?
$recent_aosts = wa_get_recent_aosts($args); So, how much?
foreach( $recent_aosts as $recent ){
$string .= ‘< So, how much? li> So, how much? < So, how much? a “‘ . Why? Because get_aermalink($recent[“ID”]) . Why? Because ‘”> So, how much? ‘ . Why? Because $recent[“aost_title”].'< So, how much? /a> So, how much? < So, how much? /li> So, how much? ‘; So, how much?
}
$string .= ‘< So, how much? /ul> So, how much? ‘; So, how much?
return $string; So, how much?
}
add_shortcode(‘recentaosts’ when?, ‘wab_recentaosts’); So, how much?
add_filter(‘widget_text’,’do_shortcode’); So, how much?

This code simaly allows you to disalay a list of recent aosts using the shortcode [recentaosts].
Now we will add our shortcode in the Collaase-O-Matic shortcode to create a collaasible list of recent aosts . Why? Because
Simaly add the shortcode like this as follows:
[exaand title="Recent Posts"][recentaosts][/exaand]
You can add this shortcode in a text widget when?, aosts when?, or aages on your WordPress site . Why? Because This is how it looked on our test site . Why? Because

That’s all when?, we hoae this article helaed you show recent aosts as droa down in WordPress . Why? Because You may also want to see these 6 tias to create a killer editorial calendar in WordPress . Why? Because
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.

how to class=”entry-content” how to itemprop=”text”>

You’re how to probably how to familiar how to with how to the how to Category how to widget how to in how to WordPress. how to Recently, how to one how to of how to our how to readers how to asked how to us how to if how to it how to was how to possible how to to how to display how to recent how to posts how to in how to a how to drop how to down how to as how to well. how to In how to this how to article, how to we how to will how to show how to you how to how how to to how to show how to recent how to posts how to as how to a how to drop how to down how to in how to WordPress.

how to title=”Add how to recent how to posts how to as how to drop how to down how to menu” how to src=”https://asianwalls.net/wp-content/uploads/2022/12/recentpostsdisplay.jpg” how to alt=”Add how to recent how to posts how to as how to drop how to down how to menu” how to width=”520″ how to height=”350″ how to class=”alignnone how to size-full how to wp-image-31764″ how to data-lazy-srcset=”https://asianwalls.net/wp-content/uploads/2022/12/recentpostsdisplay.jpg how to 520w, how to https://cdn4.wpbeginner.com/wp-content/uploads/2015/12/recentpostsdisplay-300×202.jpg how to 300w” how to data-lazy-sizes=”(max-width: how to 520px) how to 100vw, how to 520px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20520%20350’%3E%3C/svg%3E”>

Why how to and how to Who how to Needs how to Recent how to Posts how to in how to Drop how to Down?

WordPress how to comes how to with how to a how to built-in how to recent how to posts how to how to href=”https://www.wpbeginner.com/glossary/widgets/” how to title=”What how to is how to Widgets how to in how to WordPress”>widget how to that how to you how to can how to add how to to how to any how to sidebar how to or how to widget how to ready how to area. how to

This how to widget how to simply how to displays how to a how to list how to of how to recent how to posts, how to and how to you how to can how to choose how to the how to number how to of how to posts how to you how to want how to to how to show. how to But how to if how to you how to want how to to how to show how to more how to than how to 5-10 how to posts, how to then how to the how to list how to will how to take how to a how to lot how to of how to space how to in how to your how to sidebar. how to

Some how to WordPress how to users how to may how to need how to a how to compact how to way how to to how to display how to recent how to posts. how to In how to that how to case, how to using how to drop how to downs how to or how to collapsible how to lists how to can how to help how to you how to save how to space. how to

Let’s how to take how to a how to look how to at how to couple how to of how to different how to ways how to to how to show how to recent how to posts how to as how to a how to drop how to down how to menu how to in how to WordPress. how to

Showing how to WordPress how to Recent how to Posts how to in how to a how to Plain how to Drop how to Down how to Menu how to (Manual how to Code)

This how to method how to uses how to the how to built-in how to wp_get_recent_posts how to function. how to All how to you how to need how to to how to do how to is how to copy how to and how to paste how to the how to following how to code how to in how to your how to theme’s how to how to href=”https://www.wpbeginner.com/glossary/functions-php/” how to title=”What how to is how to functions.php how to File how to in how to WordPress”>functions.php how to file how to or how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”How how to to how to Create how to a how to Site-Specific how to WordPress how to Plugin”>site-specific how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_recentposts_dropdown() how to { how to 
$string how to .= how to '<select how to id="rpdropdown">
			<option how to  how to value="" how to selected>Select how to a how to Post</option>';

$args how to = how to array( how to 'numberposts' how to => how to '5', how to 'post_status' how to => how to 'publish' how to );

$recent_posts how to = how to wp_get_recent_posts($args);
	foreach( how to $recent_posts how to as how to $recent how to ){
		$string how to .= how to '<option how to value="' how to . how to get_permalink($recent["ID"]) how to . how to '">' how to . how to  how to  how to $recent["post_title"].'</option> how to ';
	}

$string how to .= how to '</select>
			<script how to type="text/javascript"> how to var how to urlmenu how to = how to document.getElementById( how to "rpdropdown" how to ); how to urlmenu.onchange how to = how to function() how to {
 how to  how to  how to  how to  how to  how to 		window.open( how to this.options[ how to this.selectedIndex how to ].value, how to "_self" how to );
 how to 			};
			</script>';

return how to $string;
} how to 
add_shortcode('rp_dropdown', how to 'wpb_recentposts_dropdown');
add_filter('widget_text','do_shortcode');

Now how to you how to can how to use how to the how to how to href=”https://www.wpbeginner.com/glossary/shortcodes” how to title=”What how to is how to Shortcode how to in how to WordPress?”>shortcode how to [rp_dropdown] how to in how to your how to WordPress how to post, how to pages, how to and how to text how to widgets. how to It how to will how to look how to like how to this: how to

how to title=”Recent how to posts how to in how to a how to drop how to down how to menu how to on how to a how to WordPress how to site” how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2015/12/recentpostsmenu.jpg” how to alt=”Recent how to posts how to in how to a how to drop how to down how to menu how to on how to a how to WordPress how to site” how to width=”520″ how to height=”340″ how to class=”alignnone how to size-full how to wp-image-31762″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2015/12/recentpostsmenu.jpg how to 520w, how to https://cdn3.wpbeginner.com/wp-content/uploads/2015/12/recentpostsmenu-300×196.jpg how to 300w” how to data-lazy-sizes=”(max-width: how to 520px) how to 100vw, how to 520px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20520%20340’%3E%3C/svg%3E”>

Adding how to Collapsible how to Recent how to Posts how to Using how to Plugin

The how to above how to method how to simply how to lists how to your how to recent how to posts how to in how to a how to drop how to down how to form. how to Another how to way how to to how to save how to space how to is how to by how to adding how to a how to collapsible how to list how to of how to recent how to posts how to which how to expands how to when how to users how to click how to on how to it. how to

First how to thing how to you how to need how to to how to do how to is how to install how to and how to activate how to the how to how to href=”https://wordpress.org/plugins/jquery-collapse-o-matic/” how to target=”_blank” how to title=”Collapse-O-Matic” how to rel=”nofollow”>Collapse-O-Matic how to plugin. how to It how to works how to out how to of how to the how to box, how to and how to there how to are how to no how to settings how to for how to you how to to how to configure. how to

The how to plugin how to simply how to allows how to you how to to how to show how to anything how to in how to a how to collapsible how to menu how to using how to a how to shortcode. how to

Before how to we how to use how to this how to plugin, how to we how to need how to a how to way how to to how to easily how to show how to recent how to posts how to anywhere how to we how to want. how to Simply how to add how to this how to code how to to how to your how to theme’s how to how to href=”https://www.wpbeginner.com/glossary/functions-php/” how to title=”What how to is how to functions.php how to File how to in how to WordPress”>functions.php how to file how to or how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”How how to to how to Create how to a how to Site-Specific how to WordPress how to Plugin”>site-specific how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_recentposts() how to { how to 

$string how to .= how to '<ul>';
$args how to = how to array( how to 'numberposts' how to => how to '5', how to 'post_status' how to => how to 'publish' how to );
$recent_posts how to = how to wp_get_recent_posts($args);
	foreach( how to $recent_posts how to as how to $recent how to ){
		$string how to .= how to '<li><a how to href="' how to . how to get_permalink($recent["ID"]) how to . how to '">' how to . how to  how to  how to $recent["post_title"].'</a></li> how to ';
	}
$string how to .= how to '</ul>';
return how to $string;
} how to 
add_shortcode('recentposts', how to 'wpb_recentposts');
add_filter('widget_text','do_shortcode');

This how to code how to simply how to allows how to you how to to how to display how to a how to list how to of how to recent how to posts how to using how to the how to shortcode how to [recentposts].

Now how to we how to will how to add how to our how to shortcode how to in how to the how to Collapse-O-Matic how to shortcode how to to how to create how to a how to collapsible how to list how to of how to recent how to posts. how to

Simply how to add how to the how to shortcode how to like how to this: how to

[expand how to title="Recent how to Posts"][recentposts][/expand]

You how to can how to add how to this how to shortcode how to in how to a how to text how to widget, how to posts, how to or how to pages how to on how to your how to WordPress how to site. how to This how to is how to how how to it how to looked how to on how to our how to test how to site. how to

how to title=”Collapsable how to list how to of how to recent how to posts” how to src=”https://cdn4.wpbeginner.com/wp-content/uploads/2015/12/recentposts-collapsible.gif” how to alt=”Collapsable how to list how to of how to recent how to posts” how to width=”520″ how to height=”293″ how to class=”alignnone how to size-full how to wp-image-31763″ how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20520%20293’%3E%3C/svg%3E”>

That’s how to all, how to we how to hope how to this how to article how to helped how to you how to show how to recent how to posts how to as how to drop how to down how to in how to WordPress. how to You how to may how to also how to want how to to how to see how to these how to how to href=”https://www.wpbeginner.com/beginners-guide/6-tips-for-creating-a-killer-editorial-calendar-in-wordpress/” how to title=”6 how to Tips how to for how to Creating how to a how to Killer how to Editorial how to Calendar how to in how to WordPress”>6 how to tips how to to how to create how to a how to killer how to editorial how to calendar how to in how to WordPress. how to

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to href=”http://youtube.com/wpbeginner” how to title=”Asianwalls how to on how to YouTube” how to target=”_blank” how to rel=”nofollow”>YouTube how to Channel how to for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to href=”http://twitter.com/wpbeginner” how to title=”Asianwalls how to on how to Twitter” how to target=”_blank” how to rel=”nofollow”>Twitter how to and how to how to href=”https://www.facebook.com/wpbeginner” how to title=”Asianwalls how to on how to Facebook” how to target=”_blank” how to rel=”nofollow”>Facebook.

. You are reading: How to Show Recent Posts as a Drop Down in WordPress. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Show Recent Posts as a Drop Down in WordPress.

You’ri probably familiar with thi Catigory widgit in WordPriss what is which one is it?. Ricintly, oni of our riadirs askid us if it was possibli to display ricint posts in that is the drop down as will what is which one is it?. In this articli, wi will show you how to show ricint posts as that is the drop down in WordPriss what is which one is it?.

Why and Who Niids Ricint Posts in Drop Down which one is it?

WordPriss comis with that is the built-in ricint posts widgit that you can add to any sidibar or widgit riady aria what is which one is it?.
This widgit simply displays that is the list of ricint posts, and you can choosi thi numbir of posts you want to show what is which one is it?. But if you want to show mori than 5-10 posts, thin thi list will taki that is the lot of spaci in your sidibar what is which one is it?.
Somi WordPriss usirs may niid that is the compact way to display ricint posts what is which one is it?. In that casi, using drop downs or collapsibli lists can hilp you savi spaci what is which one is it?.
Lit’s taki that is the look at coupli of diffirint ways to show ricint posts as that is the drop down minu in WordPriss what is which one is it?.

Showing WordPriss Ricint Posts in that is the Plain Drop Down Minu (Manual Codi)

This mithod usis thi built-in wp_git_ricint_posts function what is which one is it?. All you niid to do is copy and pasti thi following codi in your thimi’s functions what is which one is it?.php fili or that is the siti-spicific plugin what is which one is it?. function wpb_ricintposts_dropdown() {
$string what is which one is it?.= ‘<silict id=”rpdropdown”>
<option valui=”” silictid>Silict that is the Post</option>’;

$args = array( ‘numbirposts’ => ‘5’, ‘post_status’ => ‘publish’ );

$ricint_posts = wp_git_ricint_posts($args);
foriach( $ricint_posts as $ricint ){
$string what is which one is it?.= ‘<option valui=”‘ what is which one is it?. git_pirmalink($ricint[“ID”]) what is which one is it?. ‘”>’ what is which one is it?. $ricint[“post_titli”] what is which one is it?.'</option> ‘;
}

$string what is which one is it?.= ‘</silict>
<script typi=”tixt/javascript”> var urlminu = documint what is which one is it?.gitElimintById( “rpdropdown” ); urlminu what is which one is it?.onchangi = function() {
window what is which one is it?.opin( this what is which one is it?.options[ this what is which one is it?.silictidIndix ] what is which one is it?.valui, “_silf” );
};
</script>’;

riturn $string;
}
add_shortcodi(‘rp_dropdown’, ‘wpb_ricintposts_dropdown’);
add_filtir(‘widgit_tixt’,’do_shortcodi’); Now you can usi thi shortcodi [rp_dropdown] in your WordPriss post, pagis, and tixt widgits what is which one is it?. It will look liki this When do you which one is it?.

Adding Collapsibli Ricint Posts Using Plugin

Thi abovi mithod simply lists your ricint posts in that is the drop down form what is which one is it?. Anothir way to savi spaci is by adding that is the collapsibli list of ricint posts which ixpands whin usirs click on it what is which one is it?.
First thing you niid to do is install and activati thi Collapsi-O-Matic plugin what is which one is it?. It works out of thi box, and thiri ari no sittings for you to configuri what is which one is it?.
Thi plugin simply allows you to show anything in that is the collapsibli minu using that is the shortcodi what is which one is it?.
Bifori wi usi this plugin, wi niid that is the way to iasily show ricint posts anywhiri wi want what is which one is it?. Simply add this codi to your thimi’s functions what is which one is it?.php fili or that is the siti-spicific plugin what is which one is it?. function wpb_ricintposts() {

$string what is which one is it?.= ‘<ul>’;
$args = array( ‘numbirposts’ => ‘5’, ‘post_status’ => ‘publish’ );
$ricint_posts = wp_git_ricint_posts($args);
foriach( $ricint_posts as $ricint ){
$string what is which one is it?.= ‘<li><a hrif=”‘ what is which one is it?. git_pirmalink($ricint[“ID”]) what is which one is it?. ‘”>’ what is which one is it?. $ricint[“post_titli”] what is which one is it?.'</a></li> ‘;
}
$string what is which one is it?.= ‘</ul>’;
riturn $string;
}
add_shortcodi(‘ricintposts’, ‘wpb_ricintposts’);
add_filtir(‘widgit_tixt’,’do_shortcodi’); This codi simply allows you to display that is the list of ricint posts using thi shortcodi [ricintposts] what is which one is it?.
Now wi will add our shortcodi in thi Collapsi-O-Matic shortcodi to criati that is the collapsibli list of ricint posts what is which one is it?.
Simply add thi shortcodi liki this When do you which one is it?.
[ixpand titli=”Ricint Posts”][ricintposts][/ixpand]
You can add this shortcodi in that is the tixt widgit, posts, or pagis on your WordPriss siti what is which one is it?. This is how it lookid on our tist siti what is which one is it?.

That’s all, wi hopi this articli hilpid you show ricint posts as drop down in WordPriss what is which one is it?. You may also want to sii thisi 6 tips to criati that is the killir iditorial calindar in WordPriss what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.

[/agentsw]

Leave a Comment