You can do that entirely with CSS, almost no PHP coding required… try something like this:
<div id="services">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
… that way, each post will have it’s unique ID and classes… using post_class()
WordPress will add various post-related classes to the current post, such as the post type, .hentry
and various others… you can then use those classes to apply specific styles to each post
Related Posts:
- how to display full post with pagination on home page
- Showing random content / pictures from earlier posts in a sticky post?
- Displaying Latest Posts on a Page
- How to add tags (custom taxonomy) to post class css?
- How to remove in-line style of WordPress’s post content only?
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- older blog posts not showing in new theme
- WordPress Query Posts From Category Post on Static Page
- Do we still need to include a “if (have_posts())” in templates?
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- Cannot access current post’s ID in custom plugin
- Show a list of recently viewed posts to a user
- Single Post Gallery Using Shortcode
- Custom colors for post rows based on post meta value
- How to use alternate post layout at key points in post loop?
- Limit function to specific post category
- Side by side blog posts that are tied together
- How to show a full post, not just an excerpt
- Double count view in archive.php
- Different style for most recent article
- Differentiate between posts and pages in search results
- WordPress Theory Lesson – Image Columns within posts with alignment?
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- Blog Posts not showing title
- Copying and pasting emoji in a wordpress post
- Display post category in foreach loop with category link
- How To Get Posts With A Specific Word
- How to display posts on a static page? (like search loop)
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Style Differently Edited Posts
- How can i display gallery shortcode output under Post text
- WP Bakery Load More Button loads the same posts
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- problems with loading posts in a table-row
- Blog page pagination is not working after using the offset argument
- WP Query – Posts Per Page not working in combination with category__in
- More then one menu items are assigned with “current-menu-item” class
- Posting blog entries in screenplay format
- Listing Specific Categories from Current Post with Depth
- “Right Way” to make custom Loop respect reading settings inside admin panel?
- get_the_category listing in hierarchial order
- How to make a sum of all posts displayed in a loop
- Exclude current custom post on single post
- why does wordpress ignore the post args?
- First x post with another template then the others
- Loop doesn’t show title of second post and posts thereafter
- add bootstrap post slider with tabs
- How to add add more properties to WP_Post object in search results loop
- Custom taxonomy archive page problem
- Loop don’t work within single.php page
- Font shows up as Arial instead of Times [closed]
- Add Blog to WP homepage Manually
- How to show all posts by author on buddypress profile with navigation
- Getting blog pagination to work on page set as front page
- Make loop inside slider divisible [closed]
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- How to get the latest URL of my blog?
- separate the post of a category by subcategory
- How to display post list in a table layout (multiple queries in single loop)
- add div after image in post [closed]
- Not all posts showing in query
- Optimize CPT-function with a loop
- Where is the “Posts”/”Blog” template?
- Display 3 posts with different HTML markup using a loop
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- How to repeat a loop after 4 posts [duplicate]
- Direct some posts to only appear on a specific page
- Get current taxonomy and display query accordingly
- Error while excluding a post from another loop (using its ID)
- posts and cms and posts again
- Indenting within a blockquote
- Different background colors for posts with WordPress
- Turn off display for custom sidebar post widget when on the post it’s displaying
- Post Image Gallery After Content Function messes with other content
- Bulk find & replace on WordPress posts/pages (minus image paths)
- Multiple post in One Loop in wordpress
- how can i fix my display post in my index.php
- show loop id post , only first id can read
- Show post excerpt
- Wp_query loop is not working as it should
- Maximum number of posts per page before affecting performance?
- Use special template for the first post in the loop
- Display post order ranking within wordpress loop
- WordPress infinite post cycle problem
- Problem with wp_insert_post()
- How to control Post view count incresing in sidebar widget posts too?
- List of authors posts minus very latest
- How to add a class to links inside posts text
- show latest authors blog post
- Multiple Post Repeat for Related Post Loop by Category
- Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
- Loop through posts by each term and exclude duplicate posts assigned to several terms
- How can i put image to come first than the title?
- Only show posts with image and the correct ammount of posts in loop
- Is there a way to separate wordpress titles from their posts?
- Related posts by searching post tags of single post as terms
- Redirecting posts in WordPress to a specific page
- Wrap every 2 posts
- What template file is used by default for posts?