Last active
February 13, 2019 15:02
-
-
Save sanzeeb3/caac8b9d66d71970da0cab5eebe60ce5 to your computer and use it in GitHub Desktop.
List all posts in a specific page?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fu_list_all_posts() { | |
global $post; | |
// Return if the current post type is not page or the page is not blog. | |
if( $post->post_name !== 'blog' || $post->post_type !== 'page' ) { | |
return; | |
} | |
// Get all posts. | |
$all_posts = get_posts(); | |
$posts = ''; | |
foreach( $all_posts as $single_post ) { | |
$posts .= '<li><a href="'. get_permalink( $single_post ) .'">'. $single_post->post_title .' </a></li>'; | |
} | |
?> | |
<script> | |
jQuery('#page').find('#main .inner-wrap #content').append( '<?php echo $posts;?>' ); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'fu_list_all_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment