Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'genesis_after_sidebar_widget_area', 'sk_show_cpt_same_cat' );
- function sk_show_cpt_same_cat() {
- if ( ! is_singular( 'post' ) ) {
- return;
- }
- $categories = get_the_category();
- $cat_slugs = '';
- foreach( $categories as $category ) { // concatenate
- $cat_slugs .= ',' . $category->category_nicename;
- }
- echo '<section class="widget"><div class="widget-wrap">';
- // WP_Query arguments
- $args = array (
- 'post_type' => 'movies',
- 'category_name' => $cat_slugs,
- 'posts_per_page' => '2',
- );
- // The Query
- $query = new WP_Query( $args );
- // The Loop
- if ( $query->have_posts() ) {
- echo '<ul>';
- while ( $query->have_posts() ) {
- $query->the_post();
- // do something
- ?>
- <!-- Display the Title as a link to the Post's permalink. -->
- <li>
- <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
- </li>
- <?php
- }
- echo '</ul>';
- } else {
- // no posts found
- }
- // Restore original Post Data
- wp_reset_postdata();
- echo '</div></section>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement