How to show on page a list of posts tagged with the page name
-
Hi there! I couldn’t find a plug-in that did exactly what I was looking for and ended up writing the code (poorly) myself in php. I’m hoping that someone can shed some light on this.
I currently want to add a Related Resources bar to my pages that looks for posts that are tagged with the page name. For example, on the Employee Recognition page, I want to show posts that have been tagged with Employee Recognition.
Here it is, working:
http://www.scarlettpromotions.com/ILR/solutions/employee-recognition/Here is the code I used. You can see it is not optimal!
<?php if ( is_page(array('Employee Recognition', 'Sales Incentives'))) { $resourceTag=get_the_title(); ?> <?php if ($resourceTag=="Employee Recognition") { query_posts('category_name=blog&tag=employee-recognition+employee-recognition&posts_per_page=2'); } elseif ($resourceTag=="Sales Incentives"){ query_posts('category_name=blog&tag=sales-incentives+sales-incentives&posts_per_page=2'); }elseif ($resourceTag=="Recession Package"){ query_posts('category_name=blog&tag=recession-package+recession-package&posts_per_page=2'); } elseif ($resourceTag=="Celebrate Years of Service"){ query_posts('category_name=blog&tag=celebrate-years-of-service+celebrate-years-of-service&posts_per_page=2'); } ?> <?php if (have_posts()) : ?> <p style="padding-bottom:3px;">Blogs</p> <ul style="padding-bottom:10px;"> <?php while (have_posts()) : the_post(); // the Loop // the content of the post ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> <?php endif; ?> <?php if ($resourceTag=="Employee Recognition") { query_posts('category_name=white-papers&tag=employee-recognition+employee-recognition'); } elseif ($resourceTag=="Sales Incentives"){ query_posts('category_name=white-papers&tag=sales-incentives+sales-incentives'); }elseif ($resourceTag=="Recession Package"){ query_posts('category_name=white-papers&tag=recession-package+recession-package'); } elseif ($resourceTag=="Celebrate Years of Service"){ query_posts('category_name=white-papers&tag=celebrate-years-of-service+celebrate-years-of-service'); } ?> <?php if (have_posts()) : ?> <p style="padding-bottom:3px;">White Papers</p> <ul style="padding-bottom:10px;"> <?php while (have_posts()) : the_post(); // the Loop // the content of the post ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> <?php endif; ?> <?php if ($resourceTag=="Employee Recognition") { query_posts('category_name=in-the-news&tag=employee-recognition+employee-recognition&posts_per_page=2'); } elseif ($resourceTag=="Sales Incentives"){ query_posts('category_name=in-the-news&tag=sales-incentives+sales-incentives&posts_per_page=2'); }elseif ($resourceTag=="Recession Package"){ query_posts('category_name=in-the-news&tag=recession-package+recession-package&posts_per_page=2'); } elseif ($resourceTag=="Celebrate Years of Service"){ query_posts('category_name=in-the-news&tag=celebrate-years-of-service+celebrate-years-of-service&posts_per_page=2'); } ?> <?php if (have_posts()) : ?> <p style="padding-bottom:3px;">In the News Articles</p> <ul style="padding-bottom:10px;"> <?php while (have_posts()) : the_post(); // the Loop // the content of the post ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> <?php endif; ?> <?php //Reset Query wp_reset_query(); ?>
- The topic ‘How to show on page a list of posts tagged with the page name’ is closed to new replies.