Good news! I think you’re making things harder for yourself than they need to be. If I understand your question, you’re looking for rewind_posts()
. The always useful Digging Into WordPress has a nice summary of it.
Because both tasks involve looping through the same query, you don’t need get_posts()
at all.
Instead, you’ll want to use the aforementioned rewind_posts()
something like this:
<?php if( have_posts() ) : ?>
<!-- Your list of posts -->
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="https://wordpress.stackexchange.com/questions/51342/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php rewind_posts(); // second <del>verse</del> query, same as the first ?>
<?php while( have_posts() ) : the_post(); ?>
<!-- your "blog-style" stuff -->
<?php endwhile; endif; ?>
Related Posts:
- How to check if I’m on the last page of posts?
- Display list of Sub-Categories and the posts they contain, within one main Category
- Loop with Dynamic Categories
- Remove child products from woocommerce category page [closed]
- Categories list loop – add separator every year
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Display the last post by each category?
- How to insert category list into post creation page, and retrieve chosen categories?
- Categories list loop – add separator every 3 categories [closed]
- new WP_Query all post in a category inside the loop
- Getting the Most Recent Posts from Multiple Categories
- Template category.php with page (no posts)
- Order Categories by Character Count
- Rearranging posts based on categories
- WP_Query not looking at child category
- Randomise results from a category page?
- Create a full width responsive header image per page
- Get a list of commas separated categories inside a loop
- Exclude a category from the filed under list only on some templates
- Display one latest post from multiple categories
- How do I get the total number of categories in a list of search results?
- Show posts of category in a page
- Show pages and articles in category search result
- How to group the loop posts in a particular by author?
- How to create taxonomy values for pages and list them in wp-admin
- Display products for a category, sorted by post_excerpt
- Show post only if match all categories
- a-z list, categories and sub categories in loop
- Viewing category pages without the word ‘category’ in URL
- wp_dropdown_categories and custom taxonomy + custom post type
- Get all sub-categories of a parent category
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- Check child/parent categories if exists
- Displaying multiple loops based off of category
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Additional featured post on first page
- Show all posts for a specific category/author
- Redirect category to url with /category
- create a page which displays a list of categories title+ short description?
- Enter a variable in the ‘category_name’ parameter
- Hard coded main navigation
- Resort get_categories
- Query Posts Exclude Entire Category
- WooCommerce – How to show specific category first-rest of products-specific category last
- Multiple URL’s based on category for one post
- category permalinks
- List categories with custom code
- Custom category URL rewriting
- Exclude current post from loop
- How do I display something on a particular category page?
- Get the ID of 10 Latest Pages stored in a WordPress Category
- Trying to get variables in hacked category dropdown
- How to put page numbers with the next/previous on a post/category list?
- Adding category dropdown list to theme options page
- Do not show sub categories in the loop on archive-product.php
- Link To Child Category For A Post
- List a maximum of ‘x’ product categories with qty of ‘y’ in each column
- Insert HTML content in WP Query at specific point
- “Virtual category page” based on a custom field filter
- Group search results by category
- Simple way to style posts of a single category differently in the loop and in single
- Showing Categories for Page Edit – without plugin
- Using categories with pages
- Have posts that belong to multiple categories, exclude some categories from homepage
- Show multiple categories in query using redux framework variable
- Display post thumbnail for specific category outside the loop
- the_category() doesn’t working in wp_query loop
- Conditional category query breaking?
- Category sticky latest
- display specific category when website loads
- Show the number of the post
- Return all Tags and Categories in Separate List
- How can I order all subcategories alphabetical independent of the parent categories?
- How can I make a category function as a page?
- Displaying Category in sidebar post widget but not in the loop on home
- Querying posts from two different categories while looping inside another loop
- Retrieving category pages from subcategory returns empty sets
- Loop doesn’t work
- Category For Pages In WordPress
- How to loop through a custom field for each post, & display?
- show category name before first posts in each category
- Getting page/category content to show up in my custom page template
- Using wp_list_pages to create 2 lists of pages and include and exclude some of them depending on their category
- Loop through posts of CatA and store value of CatB in separate array
- How to add an empty entry to masonry?
- Pages with posts filtered by category
- Category slug in in loop always the same?
- Pages, Categories, and working with someone else’s code
- how to get number of posts in a category on a specific date
- Show posted on date only for posts in a certain category
- Page redirecting to category (IE only)
- 2 loops in archive.php (one for each category)
- Using pagination with multiple loops causes it to break
- not empty categories don’t show in menu [closed]
- Way to show content of a post, but if exceeds character limit revert to excerpt?
- list taxonomy based on taxonomy
- How to create a custom loop ordered by Categories on a Page Template?
- How can I show page per category in wordpress? (Yes, category by page!)
- Moving Blog and Changing URL
- Get categories by title descendant