wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



_post_states › WordPress Function

Seit2.7.0
Veraltetn/v
_post_states ( $post, $display = true )
Parameter: (2)
  • (WP_Post) $post The post to retrieve states for.
    Erforderlich: Ja
  • (bool) $display Optional. Whether to display the post states as an HTML string. Default true.
    Erforderlich: Nein
    Standard: true
Siehe:
Gibt zurück:
  • (string) Post states string.
Definiert in:
Codex:
Changelog:
  • 5.3.0

Echoes or returns the post states as HTML.



Quellcode

function _post_states( $post, $display = true ) {
	$post_states      = get_post_states( $post );
	$post_states_html = '';

	if ( ! empty( $post_states ) ) {
		$state_count = count( $post_states );

		$i = 0;

		$post_states_html .= ' — ';

		foreach ( $post_states as $state ) {
			++$i;

			$separator = ( $i < $state_count ) ? ', ' : '';

			$post_states_html .= "<span class='post-state'>{$state}{$separator}</span>";
		}
	}

	/**
	 * Filters the HTML string of post states.
	 *
	 * @since 6.9.0
	 *
	 * @param string                 $post_states_html All relevant post states combined into an HTML string for display.
	 *                                                 E.g. `&mdash; <span class='post-state'>Draft, </span><span class='post-state'>Sticky</span>`.
	 * @param string<string, string> $post_states      A mapping of post state slugs to translated post state labels.
	 *                                                 E.g. `array( 'draft' => __( 'Draft' ), 'sticky' => __( 'Sticky' ), ... )`.
	 * @param WP_Post                $post             The current post object.
	 */
	$post_states_html = apply_filters( 'post_states_html', $post_states_html, $post_states, $post );

	if ( $display ) {
		echo $post_states_html;
	}

	return $post_states_html;
}