Summary
How to control the big picture look and order of your WordPress posts.
1. Overview
-
WordPress blog presentation is controlled through themes, blocks, and custom code.
-
Core tools include the Site Editor, Query Loop block, and template files like
index.php
.
2. Order of Posts
-
Default order is reverse chronological (
date
descending). -
Modify order using
pre_get_posts
infunctions.php
:add_action('pre_get_posts', function($query) { if ($query->is_home()) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } });
-
Performance trade-off: Complex sorting (e.g., by meta values) may slow queries.
3. Display Types
-
Grid vs. List: Use the Query Loop block or theme templates (
content-grid.php
). -
Best practice: Cache output with Redis or WP Super Cache for dynamic layouts.
4. Search Functionality
-
Default search is basic; enhance with Relevanssi or Algolia.
-
Implementation: Add search filters via
functions.php
:add_filter('posts_search', function($search, $wp_query) { // Custom search logic here return $search; }, 10, 2);
5. Introductory Content
-
Static front page: Set in Settings > Reading (
home.php
template). -
Dynamic content: Use the Customizer or a Gutenberg block (e.g., “Post Excerpt”).
6. Featured Posts
-
Implementation: Tag posts as “sticky” or use a meta field:
$featured = new WP_Query([ 'meta_key' => 'featured', 'meta_value' => '1' ]);
-
Performance trade-off: Additional queries may impact load time.
7. Pagination Controls
-
Standard:
the_posts_pagination()
in template files. -
AJAX pagination: Use Jetpack Infinite Scroll or custom JavaScript.
8. Category & Tag Displays
-
Customize archives with
category.php
ortaxonomy-{slug}.php
. -
Best practice: Limit taxonomy queries with
'posts_per_page' => 12
.
9. Custom Post Types
-
Register CPTs in
functions.php
withregister_post_type()
. -
Display: Use the Query Loop block or a custom WP_Query.
10. Key Plugins
-
Query control: Custom Post Type UI, Toolset.
-
Performance: WP Rocket (caching), Query Monitor (debugging).
11. Performance Optimization
-
Lazy loading: Add
loading="lazy"
to images inthe_content
filter. -
Database: Optimize with WP-Optimize and limit `
To show a short version of posts in WordPress, you have several options depending on your specific needs. One common method is to use the “more” tag in the post editor. This allows you to specify where the post should be cut off, creating a shortened version with an option to read more. You can find the “more” tag icon in the toolbar of the post editor, which looks like a dotted line between two thick lines. This tag can only be used once per post.
Another approach is to use the wp_trim_words
function in your code to limit the number of words displayed. For example, you can use wp_trim_words($news_item["post_content"], 20)
to display the first 20 words of a post. However, if the content contains shortcodes, you might want to strip them first using strip_shortcodes
to ensure they are not included in the trimmed text.
Additionally, the Display Posts shortcode plugin offers features to include thumbnails, excerpts, and more. You can use the shortcode [display-posts include_excerpt="true" image_size="thumbnail"]
to display posts with an excerpt and a thumbnail.
If you are looking to show a shortened version on your blog’s home page or in feeds, you can adjust the settings in your WordPress dashboard. Go to Settings > Reading and select either “full text” or “summary” for each article in a feed.
Leave a Reply