HeWordPress Blog Presentation Overview

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 in functions.php:

    php

    Copy

    Download

    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:

    php

    Copy

    Download

    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:

    php

    Copy

    Download

    $featured = new WP_Query([
      'meta_key'   => 'featured',
      'meta_value' => '1'
    ]);
  • Performance trade-off: Additional queries may impact load time.


7. Pagination Controls

  • Standardthe_posts_pagination() in template files.

  • AJAX pagination: Use Jetpack Infinite Scroll or custom JavaScript.


8. Category & Tag Displays

  • Customize archives with category.php or taxonomy-{slug}.php.

  • Best practice: Limit taxonomy queries with 'posts_per_page' => 12.


9. Custom Post Types

  • Register CPTs in functions.php with register_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 in the_content filter.

  • Database: Optimize with WP-Optimize and limit `

Show Short Posts in WordPress

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.

Sticky Post Order Determinant

In WordPress, when multiple posts are marked as sticky, their order is determined by their post IDs rather than their publish dates. This means that the post with the lowest post ID will appear first, followed by the next lowest, and so on. However, this behavior can sometimes be inconsistent, as some users have reported that changing the publish date of a sticky post does not always affect its position.

To manage the order of multiple sticky posts more effectively, you can use plugins like the Q2W3 Post Order plugin, which allows you to sort sticky posts manually. This plugin provides a more intuitive way to arrange the order of your sticky posts according to your preferences.

Additionally, if you are using a custom query to display posts, you can include sticky posts by setting the ignore_sticky_posts parameter to false. This ensures that sticky posts are included in the query results and displayed at the top of the list. However, it is important to note that sticky posts will always appear above non-sticky posts, regardless of their position in the query.