Limited Time Offer

Save 25% on our plugins with this coupon:

LOVEWORDPRESS

Buy Now
Skip to content
TaxoPress
  • TaxoPress
  • Tag Groups
  • Docs
  • Blog
  • Support
  • Login
Buy Now
TaxoPress

TaxoPress: Getting Started

  • How to Install TaxoPress
  • Technical Requirements for TaxoPress
  • How to Activate or Deactivate TaxoPress Features
  • How to Move from TaxoPress Free to Pro
  • TaxoPress Free vs Pro
  • Capabilities / Permissions in TaxoPress

TaxoPress: Taxonomies

  • Introduction to the Taxonomies Screen
  • Taxonomies: Post Types
  • Taxonomies: Permalinks
  • Taxonomies: Admin Area
  • Taxonomies: Other Labels
  • Taxonomies: REST API
  • Taxonomies: Advanced
  • Taxonomies: Deactivate or Delete
  • Media Tags

TaxoPress: Terms

  • Introduction to the Terms Screen
  • Remove Terms From All Posts
  • Delete Terms

TaxoPress: Terms Display

  • Introduction to Terms Display
  • Show the Terms Display with a Shortcode
  • Show the Terms Display in a Widget
  • Change the Format of Terms Display
  • Add CSS to Your Terms Display
  • Show Terms Display Using PHP

TaxoPress: Current Post

  • Introduction to Terms for Current Post
  • Automatically Display Terms for Current Post
  • Options for Terms for Current Post
  • Change the Format of Terms for Current Post
  • Add CSS to Terms for Current Post
  • Show Current Post Terms With PHP

TaxoPress: Related Posts

  • Introduction to Related Posts
  • Where to Display Related Posts
  • Options for Related Posts
  • Change the Format of Related Posts
  • Add CSS to Your Related Posts
  • Show Related Posts Using PHP

TaxoPress: Auto Links

  • Introduction to Auto Links
  • Auto Links Options

TaxoPress: Auto Terms

  • Introduction to Auto Terms
  • Auto Terms Options
  • Sources for Auto Terms
  • Automatically Add New Terms
  • Automatically Add Existing Terms
  • Add Auto Terms to Existing Content
  • How to Schedule the Auto Terms Feature
  • Logs for Auto Terms
  • Use Regular Expressions to Analyze Content
  • The Auto Terms Feature on Large Sites

TaxoPress: Suggest Terms

  • Introduction to Suggest Terms
  • Using the Dandelion API for Suggest Terms
  • Using the OpenCalais API for Suggest Terms

TaxoPress: Mass Edit Terms

  • Introduction to Mass Edit Terms

TaxoPress: Manage Terms

  • Introduction to Manage Terms
  • Add Terms
  • Merge Terms
  • Rename Terms
  • Delete Unused Terms

TaxoPress: Integrations

  • Working with the Dandelion API
  • How to Register for the Dandelion API Service
  • How to Register for OpenCalais
  • Functions for Theme Integration

TaxoPress: Troubleshooting

  • Characters and Alphabets Supported by TaxoPress
  • The Auto Terms Feature on Large Sites
  • What Happened to the Click Tags Feature?
  • Troubleshooting TaxoPress Screens
  • Home
  • TaxoPress Documentation
  • The TaxoPress Plugin
  • TaxoPress: Related Posts
  • Show Related Posts Using PHP

Show Related Posts Using PHP

Table of Contents
  • Legacy PHP Code

It is possible to add the “Related Posts” output directly into your site’s PHP files.

The best approach is to use the PHP to include the shortcode inside a PHP snippet, as in this example below.

<?php echo do_shortcode("[taxopress_relatedposts id="1"]"); ?>

Legacy PHP Code #

There is also a legacy option allows you to make choices directly in the PHP code. This is the basic code snippet:

<?php st_related_posts(); ?>

Here are examples of how you can customize that basic code with more details:

'number' => 5,
'order' => 'count-desc',
'format' => 'list',
'include_page' => 'true',
'exclude_posts' => '',
'exclude_tags' => '',
'post_id' => '',
'except_wrap' => '55',
'limit_days' => '0',
'title' => __('<h4>Related posts</h4>', 'simpletags'),
'nopoststext' => __('No related posts.', 'simpletags'),
'dateformat' => $this->dateformat,
'xformat' => __('<a href="%post_permalink%" title="%post_title% (%post_date%)">%post_title%</a> (%post_comment%)', 'simpletags')

Here is an example of that legacy code in use. We want to show the first 10 related post without title, without pages and without comments count.

<?php st_related_posts('number=10&title=&include_page=false&xformat=<a href="%permalink%" title="%title% (%date%)">%title%</a>'); ?>

Here are all the legacy code parameters:

  • number
    • (integer) Number of posts to show
  • order
    • (string) Order posts sorting. Valid values are :
      • count-desc – (default) by number of common tags (most relevance)
      • count-asc – by number of common tags (less relevance)
      • date-desc – by publication’s date descending
      • date-asc – by publication’s date ascending
      • name-asc – by title ascending
      • name-desc – by title descending
      • random – random
  • format
    • (string) show tags as non ordered list UL/LI
      • flat – (Default) posts are separated with spaces
      • list – posts are inside non ordered lists containing class=’related_posts’
      • array -posts are inside a PHP array (use it with st_get_related_posts())
  • include_page
    • (boolean) “true” to add pages, “false” only for posts
  • exclude_posts
    • (string) Separate posts ID to exclude with commas
  • exclude_tags
    • (string) Separate tags ID to exclude with commas
  • post_id
    • (integer) Specified post ID for display related posts
  • except_wrap
    • (integer) Words number for excerpt.
  • limit_days
    • (string) Limit result with a max days
  • title
    • (string) Specify the positioned title before the list
  • nopoststext
    • (string) Specify the text to show when there is no related post
  • dateformat
    • (string) Specify the date format. Same format as PHP date function
  • xformat
    • (string) Extended links format. Available Markups :
      • post_date – Replaced by the date of the post
      • post_permalink – Replaced by the permalink of the link
      • post_title – Replaced by the title of the post
      • post_comment – Replaced by the comments count of the post
      • post_tagcount – Replaced by the number of common tags
      • post_id – Replaced by the ID of the post
      • post_relatedtags – Replaced by common tag list
      • post_excerpt – Replaced by post excerpt
Add CSS to Your Related Posts
Table of Contents
  • Legacy PHP Code

Recent Posts

  • How to Find the IDs of WordPress Tags, Posts or Categories May 24, 2023
  • How to Change the Design of Accordions and Tabbed Tag Clouds May 16, 2023
  • How to Add Custom Designs to Terms in Tag Groups May 15, 2023
  • Find The Most Used Tags On Your WordPress Site May 14, 2023
  • What is a Tag Slug in WordPress? May 11, 2023

Testimonials

I had a support issue and the response was same day. I find the plugin extremely fast and easy to implement.

stevenmayjr

The plugin has great features even in the free version. I had a minor issue and the plugin author replied within hours even on Sunday! Highly recommended.

Sanchit Goyal

Important Links

  • TaxoPress Demos
  • Frequently Asked Questions
  • About the TaxoPress Team
  • Terms of Service
  • TaxoPress Affiliates
  • Logo and Brand Materials

Our Projects

  • PublishPress
  • MetaSlider
  • KinshiPress
  • Ramble Ventures
  • Logtivity

© 2023 TaxoPress

Facebook Twitter
Scroll to top
  • TaxoPress
  • Tag Groups
  • Docs
  • Blog
  • Support
Search