There are two ways to achieve it.
$args = array(
'post_type' => 'post',
'posts_per_page'=>1
);
$mj_query = new WP_Query( $args );
-
By the_expcerpt(), You can use excerpt field to display the content for post listing page.You can enable excerpt field by screen option through current post edit page.Just put html element to that excerpt field and use below code. It will display it as you want.
while ( $mj_query->have_posts() ) {
the_excerpt();
}
-
By get_the_content(), you can get all content of a specific post by get_the_content() function and alter it using substr() function.Here you can use length according to you content to be displayed.
while ( $mj_query->have_posts() ) { $theExcerpt = get_the_content(); echo substr($theExcerpt,0,100);
}
Related Posts:
- How build a custom login/register form with error handling?
- external wordpress pages using wp-blog-header
- Why WordPress uses 4 tables to manage terms
- Using FirePHP with WordPress
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Append a term to WooCommerce product existing product category terms
- user_id error: Only variables should be passed by reference
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- WordPress blockquote removes “ tag
- If Meta Checkbox is checked, do something?
- Output 2 items within the Loop
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- How can I add pagination and how can I change thumbnail size?
- APC 500 Internal server error [closed]
- Call External Object in Class Function During Callback
- How can i upload images in an admin page?
- Why do WordPress rewriites seem to work differently for posts vs pages?
- Performance impact of rewriting WordPress URLs
- WordPress: Access a plugin from within a theme
- wp_ob_end_flush_all and wp_suspend_cache_addition()
- edit_comment_link is not showing for comment author
- Css loads very slow [closed]
- Why is image hard cropping for one image using add_image_size not working?
- wordpress archive a user
- How do I get around “Sorry, this file type is not permitted for security reasons”?
- How to change theme programmatically from a external application?
- Hide Featured Image Meta Box on Editor Screen
- how to test for all children (including multilevel grand-childern) of page
- Dilemma of Populating all the categories in a drop down list
- Add item to top of menu using a filter in functions.php
- How to include seperate PHP file to class in callback function
- JSON REST API WordPress only showing first 10 categories
- Password minimum length in personal subscription [closed]
- echo something inside a shortcode
- PHP include statement not working?
- require_once() if a product in woocommerce contains a tag [closed]
- How to pass a variable into an add_filter() function?
- How do I get my Javascript scripts working?
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- Only show first image in foreach loop
- How to send a HTTP Post request using PHP Curl and WordPress
- How can I find the cause of a 500 server error?
- php preg_match with multiple patterns
- Shortcode for Listing Users from Meta Value?
- I can’t update my data through $wpdb
- How to suppress template-parts in undescores?
- How run a non-WordPress PHP Program on a WordPress site?
- Wpdb get->results to out the the month from the db
- The session works on the local server, but not on the web server
- Returning all values from foreach in function php [closed]
- Display css ONLY on most recent post of specific category?
- Conditional string comparison failing for basename/slug
- Deeper editing of index.php and single.php
- add the value of a variable returned in a while loop [closed]
- Page Options Saving But Not Updating In Backend
- Using a string from a custom field within a link
- Function to add DIV Class?
- How to redirect non logged in mobile users to page on same site?
- How to WP_Query posts order by parent title?
- search.php to search only the post title
- Filter wordpress posts without searching the keywords in the post content
- REST api returns 404 on some WordPress sites
- portfolio site – about this site section – is it safe to post some code
- How do I edit the terms output args or array data?
- Change the URL of an image from wp_get_attachment_image_src for Product Posts based on Category
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Combine change Email WordPress and woocommerce emails template
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- Adding variable in WordPress shortcode
- Get custom field value from the function.php
- Non-blocking file_put_contents in function.php
- WP_QUERY post_in problem
- Call a single function on two different methods with hooks
- custom taxonomies not working
- Bring Font Awesome icons inside menu A tags
- Use WP Cron to Clear a Page Cache?
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Automatically refresh page if widget is added to page?
- Add custom taxonomy to custom search for posts
- What is wrong in this code?
- perform mathematical operation on shortcode
- WordPress / PhpStorm / XDebug and plugin_dir_path issues
- Issue adding featured image option to functions.php
- What to create new post using wp_insert_post, but it repeat the post infinitely
- Allow the execution of an external PHP script for logged users
- Get terms of the posts with one query
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- Do_shortcode on PHP file outside theme ALMOST works
- WordPress 2014 Theme – Featured Content with multiple tags?
- Get unique post in parent category
- ACF repeater image in video poster with jquery
- How to display the date under the post title?
- What is proper way to use the php if statement? [closed]
- Parse error: syntax error, unexpected ‘}’ in C:\xampp\htdocs\admin\products.php on line 148 [closed]
- Add/alter image attribute before render
- How do I do so that people can register on my wordpress site?
- Custom taxonomy pagination shows 404
- Internal server error when enabling Multisite in WordPress
- duplicating page templates
- Upload multiple files via ajax from an HTML file input