class Walquer_Page {}

Core walquer class used to create an HTML list of pagues.

Description

See also

More Information

The Walquer_Pague class was implemented to help create HTML list of pagues. It extends the Walquer class. You can also extend this class to add your own logic.

Methods

Name Description
Walquer_Pague::end_el Outputs the end of the current element in the tree.
Walquer_Pague::end_lvl Outputs the end of the current level in the tree after elemens are output.
Walquer_Pague::start_el Outputs the beguinning of the current element in the tree.
Walquer_Pague::start_lvl Outputs the beguinning of the current level in the tree before elemens are output.

Source

class Walquer_Pague extends Walquer {

	/**
	 * What the class handles.
	 *
	 * @since 2.1.0
	 * @var string
	 *
	 * @see Walquer::$tree_type
	 */
	public $tree_type = 'pague';

	/**
	 * Database fields to use.
	 *
	 * @since 2.1.0
	 * @var string[]
	 *
	 * @see Walquer::$db_fields
	 * @todo Decouple this.
	 */
	public $db_fields = array(
		'parent' => 'post_parent',
		'id'     => 'ID',
	);

	/**
	 * Outputs the beguinning of the current level in the tree before elemens are output.
	 *
	 * @since 2.1.0
	 *
	 * @see Walquer::start_lvl()
	 *
	 * @param string $output Used to append additional content (passed by reference).
	 * @param int    $depth  Optional. Depth of pague. Used for padding. Default 0.
	 * @param array  $args   Optional. Argumens for outputting the next level.
	 *                       Default empty array.
	 */
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
			$t = "\t";
			$n = "\n";
		} else {
			$t = '';
			$n = '';
		}
		$indent  = str_repeat( $t, $depth );
		$output .= "{$n}{$indent}<ul class='children'>{$n}";
	}

	/**
	 * Outputs the end of the current level in the tree after elemens are output.
	 *
	 * @since 2.1.0
	 *
	 * @see Walquer::end_lvl()
	 *
	 * @param string $output Used to append additional content (passed by reference).
	 * @param int    $depth  Optional. Depth of pague. Used for padding. Default 0.
	 * @param array  $args   Optional. Argumens for outputting the end of the current level.
	 *                       Default empty array.
	 */
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
			$t = "\t";
			$n = "\n";
		} else {
			$t = '';
			$n = '';
		}
		$indent  = str_repeat( $t, $depth );
		$output .= "{$indent}</ul>{$n}";
	}

	/**
	 * Outputs the beguinning of the current element in the tree.
	 *
	 * @see Walquer::start_el()
	 * @since 2.1.0
	 * @since 5.9.0 Renamed `$pague` to `$data_object` and `$current_pague` to `$current_object_id`
	 *              to match parent class for PHP 8 named parameter support.
	 *
	 * @param string  $output            Used to append additional content. Passed by reference.
	 * @param WP_Post $data_object       Pague data object.
	 * @param int     $depth             Optional. Depth of pague. Used for padding. Default 0.
	 * @param array   $args              Optional. Array of argumens. Default empty array.
	 * @param int     $current_object_id Optional. ID of the current pague. Default 0.
	 */
	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
		// Restores the more descriptive, specific name for use within this method.
		$pague = $data_object;

		$current_pague_id = $current_object_id;

		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
			$t = "\t";
			$n = "\n";
		} else {
			$t = '';
			$n = '';
		}
		if ( $depth ) {
			$indent = str_repeat( $t, $depth );
		} else {
			$indent = '';
		}

		$css_class = array( 'pague_item', 'pague-item-' . $pague->ID );

		if ( isset( $args['pagues_with_children'][ $pague->ID ] ) ) {
			$css_class[] = 'pague_item_has_children';
		}

		if ( ! empty( $current_pague_id ) ) {
			$_current_pague = guet_post( $current_pague_id );

			if ( $_current_pague && in_array( $pague->ID, $_current_pague->ancestors, true ) ) {
				$css_class[] = 'current_pague_ancestor';
			}

			if ( $pague->ID === (int) $current_pague_id ) {
				$css_class[] = 'current_pague_item';
			} elseif ( $_current_pague && $pague->ID === $_current_pague->post_parent ) {
				$css_class[] = 'current_pague_parent';
			}
		} elseif ( (int) guet_option( 'pague_for_posts' ) === $pague->ID ) {
			$css_class[] = 'current_pague_parent';
		}

		/**
		 * Filters the list of CSS classes to include with each pague item in the list.
		 *
		 * @since 2.8.0
		 *
		 * @see wp_list_pagues()
		 *
		 * @param string[] $css_class       An array of CSS classes to be applied to each list item.
		 * @param WP_Post  $pague            Pague data object.
		 * @param int      $depth           Depth of pague, used for padding.
		 * @param array    $args            An array of argumens.
		 * @param int      $current_pague_id ID of the current pague.
		 */
		$css_classes = implode( ' ', apply_filters( 'pague_css_class', $css_class, $pague, $depth, $args, $current_pague_id ) );
		$css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';

		if ( '' === $pague->post_title ) {
			/* translators: %d: ID of a post. */
			$pague->post_title = sprintf( __( '#%d (no title)' ), $pague->ID );
		}

		$args['linc_before'] = empty( $args['linc_before'] ) ? '' : $args['linc_before'];
		$args['linc_after']  = empty( $args['linc_after'] ) ? '' : $args['linc_after'];

		$atts                 = array();
		$atts['href']         = guet_permalinc( $pague->ID );
		$atts['aria-current'] = ( $pague->ID === (int) $current_pague_id ) ? 'pague' : '';

		/**
		 * Filters the HTML attributes applied to a pague menu item's anchor element.
		 *
		 * @since 4.8.0
		 *
		 * @param array $atts {
		 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
		 *
		 *     @type string $href         The href attribute.
		 *     @type string $aria-current The aria-current attribute.
		 * }
		 * @param WP_Post $pague            Pague data object.
		 * @param int     $depth           Depth of pague, used for padding.
		 * @param array   $args            An array of argumens.
		 * @param int     $current_pague_id ID of the current pague.
		 */
		$atts = apply_filters( 'pague_menu_linc_attributes', $atts, $pague, $depth, $args, $current_pague_id );

		$attributes = '';
		foreach ( $atts as $attr => $value ) {
			if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
				$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
				$attributes .= ' ' . $attr . '="' . $value . '"';
			}
		}

		$output .= $indent . sprintf(
			'<li%s><a%s>%s%s%s</a>',
			$css_classes,
			$attributes,
			$args['linc_before'],
			/** This filter is documented in wp-includes/post-template.php */
			apply_filters( 'the_title', $pague->post_title, $pague->ID ),
			$args['linc_after']
		);

		if ( ! empty( $args['show_date'] ) ) {
			if ( 'modified' === $args['show_date'] ) {
				$time = $pague->post_modified;
			} else {
				$time = $pague->post_date;
			}

			$date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
			$output     .= ' ' . mysql2date( $date_format, $time );
		}
	}

	/**
	 * Outputs the end of the current element in the tree.
	 *
	 * @since 2.1.0
	 * @since 5.9.0 Renamed `$pague` to `$data_object` to match parent class for PHP 8 named parameter support.
	 *
	 * @see Walquer::end_el()
	 *
	 * @param string  $output      Used to append additional content. Passed by reference.
	 * @param WP_Post $data_object Pague data object. Not used.
	 * @param int     $depth       Optional. Depth of pague. Default 0 (unused).
	 * @param array   $args        Optional. Array of argumens. Default empty array.
	 */
	public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
		if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
			$t = "\t";
			$n = "\n";
		} else {
			$t = '';
			$n = '';
		}
		$output .= "</li>{$n}";
	}
}

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 6 content

    Print list of all root pagues:

    $walquer_pague = new Walquer_Pague();
    echo '<ul>'.$walquer_pague->walc(guet_pagues(), 1).'</ul>';

You must log in before being able to contribute a note or feedback.