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
- Print Current Post Index number within Loop
- Should we trust the post globals?
- How to get posts published between a date and today?
- How set featured posts using checkbox in post edit screen?
- Get first post from wp_query
- How to add a “last” class to the last post in loop.php?
- Do we still need to include a “if (have_posts())” in templates?
- WP_Query: Why is sticky post not first item in loop?
- Is it possible to bold certain words in a post title?
- Query *only* sticky posts
- Display all posts from specific categories on a page
- Disable WordPress’ blogging functionality and disable ‘posts’
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- Skip post in loop and mixin later
- How to show list of posts by author and category?
- Override the default number of posts to show for a single loop?
- get comments and get posts in loop
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Is this the best (and only) option to style CSS for a given post type?
- Display content from a specific category
- Reverse chronology of post listing
- Why do I need to use The Loop on pages (inside page.php etc)?
- posts page – different lengths of excerpt
- How do I convert a mathematical Microsoft Word document to a WordPress blog post?
- WordPress Number of Posts Not Changing With posts_per_page
- widget should display post archive by year and on click also by month
- adding a custom css class to post
- Count singular post views automatically
- Looping through posts per category gives same posts for each category
- Find most recent authors
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Display All Sticky Post Before Regular Post
- Cannot access current post’s ID in custom plugin
- Can’t show comments count per post outside loop
- Get the author of the latest revision
- blog page showing only first post
- How to have different content in the loop and single
- Specific loop in Shortcode
- Strange switch_to_blog() issue
- Show a list of recently viewed posts to a user
- Multiple loops in same page, without duplicate content
- Single Post Gallery Using Shortcode
- Custom colors for post rows based on post meta value
- loop not displaying posts on custom template page
- Repost post on specific date every year
- How to use alternate post layout at key points in post loop?
- Alternate custom content in the loop
- Search widget breaks when using multiple loops?
- How to Display Post View Count
- How to share same post to multiple site in wordpress?
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- Hide add new page button
- Limit function to specific post category
- Side by side blog posts that are tied together
- Display Latest Post from all Categories
- Auto Refresh Post List after X seconds
- How to show a full post, not just an excerpt
- The correct way to call posts with ajax
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- custom wordpress post loop – hide iframe content
- Double count view in archive.php
- Divide Loop Into Days & Categories
- Converting multiple loops into one single loop with pagination
- Display posts with comments closed, with pagination?
- Group posts by year in loop
- How would I get 1 latest post from a query for 5 posts?
- Latest 5 posts (custom post type), each post different CSS
- Custom excerpt length filter doesn’t work
- How to get the post’s parent ID?
- While in “the loop”, detect if a post is the most recent
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- Different style for most recent article
- Contact form 7 post loop [closed]
- Differentiate between posts and pages in search results
- WordPress Theory Lesson – Image Columns within posts with alignment?
- Limit Gutenberg blocks available to users to choose from
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- Loop through all product posts?
- How to style the last post on the front page different than the others?
- How to display different number of posts
- If Specific Post, Link Elsewhere
- Add a class to post title if a link ends with a certain extension
- How to filter posts that belong to a specific category only if that is the only category
- WP Query – duplicated posts once including tags in search results
- Most recent post from another database
- wp_tag_cloud() and the_taxonomies() work but not the_tag()
- Blog Posts not showing title
- Copying and pasting emoji in a wordpress post
- get_next_post() and get_previous_post() return wrong posts