I am trying to print the categories attached to the post chosen by the random post widget, but my code do not print those categories, but some else, and the same each time the random post is generated:
// Get the random posts.
$random = arpw_get_random_posts( $instance, $this->id );
// Check if the random posts exist
if ( $random ) :
// Output the theme's $before_widget wrapper.
echo $before_widget;
// If both title and title url is not empty, display it.
if ( ! empty( $instance['title_url'] ) && ! empty( $instance['title'] ) ) {
echo $before_title . '<a href="' . esc_url( $instance['title_url'] ) . '" title="' . esc_attr( $instance['title'] ) . '">' . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . '</a>' . $after_title;
// If the title not empty, display it.
} elseif ( ! empty( $instance['title'] ) ) {
echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
}
// Get the random posts query.
echo $random;
for ($x = 0; $x <= 4; $x++) {
$cat_id =$instance['cat'][$x];
echo get_cat_name ($cat_id);
}
Aucun commentaire:
Enregistrer un commentaire