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 fix pagination for custom loops?
- Jquery Slider for profile template
- Counting the posts of a custom WordPress loop (WP_Query)?
- if ( is_home() && ! is_front_page() )
- Get excerpt using get_the_excerpt outside a loop
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- Get post content from outside the loop
- Why should I put if(have_posts()), is while(have_posts()) not enough?
- Display featured products through custom loop in woocommerce on template page
- Split Content and Gallery
- How to get Author ID outside the loop
- How can i display the content in plaintext
- Redirect loop when trying to login to /wp-admin/ [duplicate]
- How to split a loop into multiple columns
- Is it necessary to reset the query after using get_posts()?
- Is there any difference between the_title() and echo get_the_title()?
- AJAX with loop filtering categories
- Style something only on the home page
- Do I need to use The Loop on pages?
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- How to force excerpts / teasers in the loop
- Retrieve each widget separately from a sidebar
- Getting Post Comments for post ID using WP_Query() and a Custom Loop?
- Why am I being limited to ten posts on a custom loop?
- How to add a “last” class to the last post in loop.php?
- Should I use loop in the single.php file?
- A search for ‘0’ returns results
- Why do themes rely on “The Loop”?
- How to return loop contents
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Cleanest Way to Select Every Second Element in a Loop?
- Insert image or ad script after 3 posts using the loop
- Get date of last update outside of loop
- Child Pages Loop
- How to place comments_template(); outside the loop?
- Multiple Loops Homepage?
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- How to get the first image gallery of a product in woocommerce in a loop
- Get post by page name or slug
- save_post + insert_post = infinite loop
- Loop.php vs looping inside template file
- Get ID of a page containing secondary loop in content
- Custom Loop and Infinite Scroll
- Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- the_content and wp_link_pages
- Adding ‘current_post_item’ class to current post in the loop
- How do I get the attributes of a short code from a post?
- How can I custom order the results from wp_list_categories?
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- WooCommerce Product Page Loop – Output All Product Thumbnails
- wp-admin redirecting to https, denying login
- Endless loop with wp_insert_post and wp_update_post
- Display subpages under parent page as a list within a loop
- Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]
- When to use wp_reset_postdata();
- Is including the loop necessary for page.php? [duplicate]
- the_title(); works in a page template, outside the loop. Why?
- wordpress loop for specific category
- Add 20yrs to post date, and then query
- Why do themes have `while( have_posts() )` in templates like single.php?
- When and Why is is_singular(‘my_cpt’) true while in_the_loop() is false?