Skip to content

Instantly share code, notes, and snippets.

@sanzeeb3
Last active February 13, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanzeeb3/caac8b9d66d71970da0cab5eebe60ce5 to your computer and use it in GitHub Desktop.
Save sanzeeb3/caac8b9d66d71970da0cab5eebe60ce5 to your computer and use it in GitHub Desktop.
List all posts in a specific page?
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