Skip to content

Commit

Permalink
Make tagged posts viewable on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 20, 2024
1 parent bd64767 commit b45c049
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
26 changes: 21 additions & 5 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Frontend {
*/
public $author = false;

/**
* Whether an tag is being displayed
*
* @var object|false
*/
public $tag = false;

/**
* Whether a post-format is being displayed
*
Expand Down Expand Up @@ -1410,8 +1417,14 @@ public function friend_posts_query( $query ) {
break;

case 'tag':
$post_tag = array_shift( $pagename_parts );
$tax_query = $this->friends->wp_query_get_post_tag_tax_query( $tax_query, $post_tag );
if ( empty( $pagename_parts ) && $page_id ) {
// Support numeric tags.
$this->tag = strval( $page_id );
$page_id = false;
} else {
$this->tag = array_shift( $pagename_parts );
}
$tax_query = $this->friends->wp_query_get_post_tag_tax_query( $tax_query, $this->tag );
break;

default: // Maybe an author.
Expand Down Expand Up @@ -1476,9 +1489,12 @@ public function friend_posts_query( $query ) {
$query->set( 'page_id', $page_id );
if ( ! $this->author ) {
$post = get_post( $page_id );
$author = User::get_post_author( $post );
if ( false !== $author ) {
$this->author = $author;

if ( $post ) {
$author = User::get_post_author( $post );
if ( false !== $author ) {
$this->author = $author;
}
}
}
$query->is_single = true;
Expand Down
9 changes: 9 additions & 0 deletions templates/frontend/main-feed-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
$_title
)
);
} elseif ( $args['friends']->frontend->tag ) {
echo esc_html(
sprintf(
// translators: %1$s is a hash tag, %2$s is a type of feed, e.g. "Main Feed".
_x( '#%1$s on %2$s', '#tag on feed', 'friends' ),
$args['friends']->frontend->tag,
$_title
)
);
} else {
echo esc_html( $_title );
}
Expand Down

0 comments on commit b45c049

Please sign in to comment.