Skip to content

Function PHP st_related_posts

Amaury Balmer edited this page Jun 17, 2013 · 1 revision

Description and usage

With this functionnality, you can show related posts on your post. Is related posts which have at least one common tag. If you don't wish to show related posts, but use them inside the loop, use st_get_related_posts() function.

Usage

<?php st_related_posts(); ?>

Default Usage

'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')

Example

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>'); ?>

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