Last active
August 29, 2015 14:05
-
-
Save nielsvr/ad6f7d36b18d2e6a33da to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function display_posts_function() { | |
$return = ""; | |
$cats = get_categories('hide_empty=0&orderby=name&order=asc'); | |
foreach ($cats as $cat) : | |
$return .= '<ul class="list"><li class="name-cat"><a href="' . get_category_link( $cat->term_id ) . '" title="' . $cat->name . '" >' . $cat->name . '</a></li>'; | |
$args = array( | |
'posts_per_page' => -1, // max number of post per category | |
'cat' => $cat->term_id | |
); | |
$posts = get_posts($args); | |
if ( count($posts) > 0 ) : | |
foreach( $posts AS $single_post ) : | |
$return .= '<li class="name-post">'; | |
$return .= '<a href="'.get_permalink( $single_post->ID ).'" rel="bookmark">'.get_the_title( $single_post->ID ).'</a>'; | |
$return .= '</li>'; | |
endforeach; | |
endif; | |
$return .= '</ul>'; | |
endforeach; | |
return $return; | |
} | |
function register_shortcodes(){ | |
add_shortcode('myshortcode', 'display_posts_function'); | |
} | |
add_action( 'init', 'register_shortcodes'); | |
// [myshortcode] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment