You can use the has_tag function in a conditional statement to achieve what you want. Take a look at the codex page here:
Function Reference/has tag.
This isn’t 100% tailored to your specific question, but you should see how it’s working and adjust for your specific task:
<?php if( has_tag() ) { ?>
<?php query_posts( 'cat=1&posts_per_page=5' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="has-tags">
<ul id="the-tags"><?php the_tags(); ?></ul>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<?php
} else {
// Whaterver else you're doing here.'
} ?>
Related Posts:
- Exclude posts based on an array
- Query posts and display all dates in repeater field in chronological order
- How to fix pagination for custom loops?
- How to get Author ID outside the loop
- Remove the Homepage Query
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Transient not working for custom loops
- post__in – Placing content from a foreach loop inside of an array
- post loop causes wp_users and wp_usermeta DB queries for each users
- get_the_foo() in the loop – does it perform another query?
- If No Search Results, Show Posts from Alternate Search Query
- How to Loop within a Loop (Display Children and then Grandchildren)
- Loop posts only excluding first post
- Loop after page content
- A loop with all articles with certain text strings in tags
- How can i use the same template file with a widget and category loop?
- Display most viewed post from last 30 days is not working correctly
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- How to go about combining dropdowns / filter queries?
- Query reset problem or flawed code to enable custom post type query
- Query last updated posts (posts updated in the last 24 hours)
- Conditional query that displays on Woo product attribute pages
- How do I use AJAX Query in my posts loop?
- woocommerce get_price_html not pulling in correct price
- How to fix pagination for custom loops?
- How can I paginate this?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- How to fix pagination for custom loops?
- Split wordpress loop to multiple layouts
- Problem with displaying HTML content after in_array [closed]
- Making a query to the DB using same parameters of loop
- Include current post into loop
- Array ids post to function have_post
- Can’t access PHP array inside script localization from javascript
- Loop inside query
- Output meta into arrays
- Trying to get property of non-object in shortocde
- How to append a query string to pagination?
- How can I access specific posts brought back by query_posts?
- How to create a multidimensional array with multiple loops
- How to get user ID’s from multiple usernames?
- Loop through an array inside a class using foreach [closed]
- get_delete_post_link() inside Loop stubbornly returns nothing
- WordPress Alphabetical Sort Loop Issue
- loop inside the foreach
- Query posts only with actual text content (not including shortcode or images)
- CPT while loop not working
- display post tags on single.php inside loop
- Query post & loop problem.
- Loop info in jquery Tabs – loop into a variable?
- Add 2 values to post__not_in
- Loops for cat links not looping for wordpress site
- How do I set the Stewart Search Template to return only published posts in the result
- Trying to get all links in my posts
- Custom Query with Sticky Posts
- Build a Page which shows the Oldest Post with specific Custom Field Value
- How to fix pagination for custom loops?
- Get featured image outside the loop using foreach
- Alternative layout the loop
- Show posts by tags excluding current post
- Strange problem with wp_get_attachment_image_src database (db) query count
- Issue with WP_Query (need a array of selected ID’s)
- Next 10 posts data of currently viewing post in blog page
- How to fix pagination for custom loops?
- Can’t print out returned value
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- Get query result before posts are displayed?
- Using class id from array for query
- Combine Query and Select Database to create directory loop
- wordpress showing all posts instead of date range
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- WordPress loop put title into variable
- Multiple loop with pagination in same page
- How to store wordpress title in a variable
- Query parsing only author ids
- How to get files from loop for zip
- Query Loop Block: possible to restrict just child pages?
- How to set and retrieve cookies while in the loop
- Use Base-URL with Query-Loop
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Why do themes have `while( have_posts() )` in templates like single.php?
- Too many nested wp_query loops in this hypothetical query?
- WordPress Loop – Style rows of posts differently
- Only display videos and images in the_content() within loop
- Publish Categories for a particular Author on a given Post
- Get paged outside of loop?
- Show scheduled posts in loop (but don’t link to them)?
- How to get a count of all posts in foreach loop and split into fourths
- Issue with custom loop in Archive page
- How to loop through yoast primary categories? [closed]
- WordPress get post thumbnail url
- linking to post outside the loop
- Can’t get the previous and next posts permalink
- Modifying a Loop to Show More
- Adding options to loop
- Adding Category Argument into an Array for WordPress Query
- How to get current page id and compare it to looped pages inside the same page?