Search the Community
Showing results for tags 'related posts'.
-
Im running a website about health and foods. I would like that at the end of each article, it shows other related articles that I have on my website. Im relatively new with php and mysql so I figure I have to put every page onto a database table. I looked already everywhere but all I found is how to do with wordpress. But i'm not using anything like that. I made the website myself with css and html and php. Can somebody help me with a website where they explain how to do? Also I would like that automatically it shows my latest articles in a sidebar. Without anytime adding myself manually. Can anybody help me?
- 2 replies
-
- posts
- related posts
-
(and 2 more)
Tagged with:
-
Hey Everyone. I am hoping this is the right place to ask this question. I am using a new WordPress theme and it has native related post coding in it. The problem is the code uses Post Tags as the selection value instead of Post Category. I was wondering if anyone could help me with this strip of code. I want to change it so the theme gets Posts in the same Category, instead of Posts with the same Tags. * Display related posts. * * @return void */ function stag_related_posts() { global $post; if( stag_rcp_user_has_no_access() ) return; if( ! stag_theme_mod( 'post_settings', 'show_related_posts' ) ) return; $tags = wp_get_post_tags( $post->ID ); if ( count( $tags ) ) { $tags_ids = array(); foreach($tags as $individual_tag) { $tag_ids[] = $individual_tag->term_id; } $query = new WP_Query( array( 'tag__in' => $tags_ids, 'post__not_in' => array( $post->ID ), 'posts_per_page' => absint( stag_theme_mod( 'post_settings', 'related_posts_count' ) ), 'caller_get_posts' => 1 ) ); // Add filter to attach 'post-grid' class add_filter( 'stag_showing_related_posts', '__return_true' ); if( $query->have_posts() ) : echo '<section class="related-posts" data-layout="2-2-2-2">'; while( $query->have_posts() ) : $query->the_post(); get_template_part( 'content', get_post_format() ); endwhile; echo '</section>'; endif; } wp_reset_query(); remove_all_filters( 'stag_showing_related_posts' ); } I've tried simply replaces the words Tags with Categories, but it doesn't seem to do much. Any help would be greatly, greatly, appreciated.