<?php
$homePosts = new WP_Query(array(
'posts_per_page' => 5
));
$count = 1;
while ($homePosts->have_posts()) {
$homePosts->the_post();
if ( $count % 2 == 0 ) {
$class="right";
} else {
$class="left";
}
?>
<section class="align-<?php echo $class; ?>" >
<div class="content">
<?php the_title(); ?>
<?php the_content(); ?>
</div>
</section>
<?php
$count++;
} wp_reset_postdata();
?>
You can try this code
Related Posts:
- How do I get the current edit page ID in the admin?
- Does hooking into the same action multiple times drain memory?
- Apply custom role capabilities to administrator (without plugin)
- Different wp_mail_from and wp_mail_from_name for specific situations
- register_post_type for Pages?
- Linking thumbnail to full size image
- is_front_page not working in functions.php
- VERY new to coding – keep breaking site trying to add to functions.php
- Restrict user registration to emails on a single domain
- Call to undefined add_action() in theme’s functions.php
- How to enqueue JavaScript for specific WordPress pages only?
- Passing HTML in WordPress Shortcode arguments
- Can I use require() function in a template file?
- What is the most efficient method for loading widgets in functions.php
- Enqueue script o style only if a template part is loaded
- Functions.php reverted to new one
- Exclude Empty Child Categories in Menu
- Convert User ID’s to User Names in a single.php file
- Custom roles can’t access to wp-admin
- How to specify which Gutenberg blocks are available in the editor for a page template
- password protected post policy
- Custom Shortcode, functions PHP WP_Query loop
- Add class or ID to any WordPress function
- How to filter out shortcode when displaying the_excerpt() in the loop?
- wpautop – disable tags, keep tags
- Logout hyperlink within a sub-menu
- How do I pass arguments for multiple functions hooked to a single action?
- Manipulate Permalink
- Change the HTML of the comment form that is generating somewhere from the core WordPress
- Toggle User Roles with button
- How to make custom column Admin>Users sortable?
- Theme functions.php file auto delete everyday [closed]
- How to get the index number of the posts?
- Two Types of settings in WP – The Doubt
- How to filter $content in shortcode function
- Custom Attachment Caption Fields
- Generating dynamic css into custom file [closed]
- How to call particular funcion when the check box is checked in plugin options page
- Call WordPress function outside of WordPress
- Difficulty with PHP function that displays a post’s format in WordPress
- Events: Check for other event with same start date and category [closed]
- enqueue_script with filemtime javascript not working
- WP function won’t work on 404 template page
- Function coding error concatenating quotes I think
- Need print logo without any ID & class
- Can we create our own theme’s function.php?
- Not all CSS elements transferring via parent to child?
- Reset postdata not working on WP_Query in functions.php
- Filter nav menu items HTML tags and wrap inner text with span
- Using Static HTML instead of the `home_url()` WP function
- How to append classname to body tag if guest user
- add_filter to specific WooCommerce Category
- Need To Change WordPress Meta Tags… Includes wordpress shortcodes
- Can I include a custom PHP function in a WordPress function?
- Adding a section in line at the end of the main navigation menu in php
- Function to replace comment’s accented characters before posting
- wp_nav_menu work in functions.php but not in the theme
- Only echo Page Content (not page title & page content together)
- update_post_meta is Updating with two page id
- How do I preserve changes to a theme’s functions.php across updates?
- Unable to Change “Pages:” Before WP_LINK_PAGES
- Looking for Functions File that doesn’t Exist
- sort metabox columns in listing Single
- Fetch URL parameter
- Updating custom query var with multiple values
- Redirect to one of two pages after data submitted, depending on the current url
- WordPress wp_dequeue_script remove all other scripts
- Error in “class-wp-hook.php”
- Add Javascript code to functions.php childtheme
- Ajax in plugin fails – but only on one blog – no idea why
- Why does my wp_enqueue_script() only insert the script for logged in users
- how to remove a tag in the_category function
- Load CSS file conditionally
- my wordpress doesn’t save items to customized widget area
- Copying a widget class to functions.php results on a blank page
- save_post doesn’t correctly process function call with php class
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Changing the register url is not working
- Newest comments first not working
- Pass arguments to function class with do_action()
- How to a override parent theme page that has been included with require_once?
- Display most popular posts
- Can I use a function to return HTML and the result of another function?
- Excerpt length: get 2 paragraphs
- Remove heading tags on line break
- Add custom fields after post/page title
- Ajax call does not work for this custom code
- Force resize for all video content
- Sort results by name & asc order on homepage
- Add the title of a widget as an ID – for anchor links
- I want to add the alt attribute to all the photos!
- Creating mixture of shortcodes to use in the visual/text editor
- Correct php syntax to add an image in wp functions.php
- User’s Comments Number: Storing it in a meta field for different uses
- Show one post per author and order by custom field
- Text before price on WooCom
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Change Post status based on custom field date +1 day
- How to add height and width dimensions automatically to archive descriptions
- How to store page-{id}.php templates in custom folder