-
-
Save muks999/13f3f0809ae4496f191b3d85fe67a778 to your computer and use it in GitHub Desktop.
Шорткод вывода постов по ID
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
add_shortcode( 'art_related_posts', 'related_posts_function' ); | |
function related_posts_function ($atts){ | |
$atts = shortcode_atts( array( | |
'id' => '', | |
'count' => 3 | |
), $atts ); | |
$args = array( | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'posts_per_page' => $atts['count'], | |
'include' => $atts['id'] | |
); | |
$out_posts = get_posts( $args ); | |
$out = '<style> | |
.art-rp{ | |
background: #ddd; | |
padding: 20px 20px; | |
} | |
</style>'; | |
$out .= '<ul class="art-rp">'; | |
foreach ($out_posts as $post) { | |
setup_postdata( $post ); | |
$out .= '<li><a href="'. get_the_permalink($post->ID) .'">'. get_the_title( $post->ID ) . '</a></li>'; | |
} | |
$out .= '</ul>'; | |
wp_reset_postdata(); | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment