The best way to do this is get the post format and then use the switch statement, like this:
$my_format = get_post_format ();
switch ($my_format) {
case 'quote': $htmlcontent = ... ; break;
case 'aside': $htmlcontent = ... ; break;
and so on
}
The function that builds up $htmlcontent starts with declaring some building blocks that are used later on (from $timeformat to $firsttext). You can improve on this by setting up larger blocks. The code as it is now, for instance, would already be better if it had blocks like this:
$post-title="<header class="content">
<h2 class="post-title"><a href="". get_permalink(get_the_ID()) .'">'. get_the_title() .'</a></h2>
</header>';
This code is now duplicated, which is never a good idea.
Related Posts:
- Remove the Homepage Query
- Pagination not working on home page
- is_home, and is_front_page conditional problem
- Post Format single-loop.php using get_template_part
- Better way to display posts from specific categories, in a grid layout
- Targeting a Certain Post in Loop (CSS)
- How do I get row padding in a post feed?
- Recent posts on a static home page
- Next Posts Prev Posts for Standard post format only
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- Can I add generic numbering HTML classes to items as a loop runs?
- Is there any good reason for two CSS files to @import each other?
- something strange is happening to my code
- display post format text in loop
- How do I put my frontpage featured image in a page template for home.php?
- get_template_part() Not Working in Loop
- WordPress loop not working only on home page, works on all other pages
- Adding first and last classes to three column layout in Bones boilerplate
- WP_Query is only looping home page, not pages
- Video post format, extra content breaks video embed
- Thumbnail Image Rounded Corners w CSS (or any other good method)
- Skip 5 latest post while paging?
- Insert content above an embedded video inside Wordress’ php the_content
- WordPress posts in the loop not stacking side by side
- Return only one post format in index.php [duplicate]
- Homepage Loop Somehow Breaks Styling Of Post Grid
- Echo Most Recent Sticky Post in Loop?
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Add Div IDs dynamically to CSS
- 2 loops in blog homepage
- Home page loop with pagination problem
- Loop doesn’t give the thumbnail the right parent (or class)
- Different style for first two (sticky) posts
- Problem with ms-thumb-frame-selected class in Master Slider
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- How to get Author ID outside the loop
- remove tags from the_content
- Why do themes rely on “The Loop”?
- How to place comments_template(); outside the loop?
- Endless loop with wp_insert_post and wp_update_post
- Hook into the loop via a plugin, and output something after every X post?
- Two custom loops, pagination, offset
- Access to Media Library
- Getting two wp_link_pages output
- post loop causes wp_users and wp_usermeta DB queries for each users
- Ajax loop refresh on click
- Run The Loop over array of post objects
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Enable infinite scroll on single.php [closed]
- How to retrieve “sticky” post outside the “loop”?
- code suddenly appearing from my tempate second loop
- Get post/page data outside the loop
- style.css doesn’t load on the home page when front-page.php activated (using stock theme)
- woocommerce get_price_html not pulling in correct price
- Trouble Formatting DateTime
- Order archive results by post id in custom taxonomy template
- How to fix pagination for custom loops?
- pre_get_posts for two loops on same page
- Modify the main loop to display current month / year
- two columns of posts on homepage, one of them “favorites”
- Problem with displaying HTML content after in_array [closed]
- Loop for sticky posts
- Get author_id in wordpress
- Single.php different behaviour from admin to non-admin
- Array ids post to function have_post
- Can’t access PHP array inside script localization from javascript
- ACF – add a group inside a repeater [closed]
- Get post offset/posts page offset in single post page (outside the loop)
- get_comments with post_status ‘public’ retrieves NULL result
- Content Visibility for WordPress is not working (Drafts, public etc.)
- Generating a perfect loop
- I have broke my pagination, same posts on all pages (index.php)
- I need to display all post in onepage
- Category ID returns as ‘0’?
- make get_post work in the loop
- For Each +1 WordPress Loop
- How to separate each individual blog post?
- Loops for cat links not looping for wordpress site
- WordPress: query pages except remove one page
- get_post_meta printing empty fields, but it shouldn’t be
- Is it possible to set archive.php instead of index.php to display blog?
- How to read taxonomy in loop?
- get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
- how to add 4 post in one carousel slide
- Exclude Posts Using Meta Query and User Meta
- Is “the loop” a template tag?
- Show a list of user posts in the user admin page
- WordPress with woocommerce custom query
- Page gets displayed in post field
- Active class for my flexslider in WordPress
- get_template_part() to render single page Theme
- Can’t see custom field after the Loop [closed]
- Showing related posts (custom post type) outside of the loop
- Same Loop on Multiple Pages
- The Loop for my theme with static front page is not working
- WordPress loop: Display if posts exist
- strange parse error when including a loop template within another template
- Showing ads after posts in home page
- wp_mail function not working in user query loop
- How to set and retrieve cookies while in the loop