Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="column-b">
- <span class="posts-title">Related Articles</span>
- <?php global $post;
- $cat = get_the_category( $post->ID );
- if ($cat){
- $cat_id = $cat[0]->cat_ID;
- }
- else{
- $cat_id = 1; // Тут задается дефолтная категория
- }
- $args = array( 'numberposts' => '2', 'category' => $cat_id );
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <div class="item-post">
- <?php
- $thumb = get_post_thumbnail_id();
- $img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
- $image = $img_url; //resize & crop the image
- ?>
- <?php if($image) : ?>
- <div class="blog-item-img"><a href="<?php the_permalink(); ?>"><img alt="<?php the_title(); ?>" src="<?php echo $image ?>"/></a></div>
- <?php endif; ?>
- <h2>
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </h2>
- <p><?php the_category(', ') ?></p>
- <p class="post-desc"><?php echo excerpt(15); ?></p>
- </div>
- <?php endforeach; ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement