Skip to content

Internal Shortcode | [Final_end]

EkoJr edited this page Mar 17, 2017 · 2 revisions

Description

Removes the substring (content) after [final_end] tag when displaying the last item (Post/Page) in the post list. For example, excluding the last comma as a separator.

Usage

[final_end]

Return

(string) Formatted string to display.

Examples/Sample

Example 1

[final_end]

Returns

(returns formatted Post List)

Source

File: advanced-post-list/includes/class/apl_shortcodes.php

/**
 * Final End Post List Shortcode. 
 * 
 * Desc: Determines the End of the Final post to display. 
 * 
 * 1. Get everything except everything after the last Final_End. 
 * 2. Strip all Final_End shortcodes. 
 * 3. Return string. 
 * 
 * @since 0.3.0 
 * @version 0.4.0 - Changed to Class function, and uses WP's built-in 
 *                  functions for setting default attributes & do_shortcode(). 
 * 
 * @param array $atts {
 *      
 *      Shortcode Attributes. 
 *      
 *      @type integer $content      Preset Content that will be displayed. 
 * }
 * @return string Preset (Post List) Content. 
 */
public function final_end($content)
{
    //INIT
    $return_str = '';
    
    //STEP 1
    $return_str .= substr($content, 0, strrpos($content, "[final_end]"));
    
    //STEP 2
    $return_str = str_replace('[final_end]', '', $return_str);
    
    //STEP 3
    return $return_str;
}

Additional Resources

Clone this wiki locally