Post.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\View\Composers;
  3. use Roots\Acorn\View\Composer;
  4. class Post extends Composer
  5. {
  6. /**
  7. * List of views served by this composer.
  8. *
  9. * @var array
  10. */
  11. protected static $views = [
  12. 'partials.page-header',
  13. 'partials.content',
  14. 'partials.content-*',
  15. ];
  16. /**
  17. * Data to be passed to view before rendering, but after merging.
  18. *
  19. * @return array
  20. */
  21. public function override()
  22. {
  23. return [
  24. 'title' => $this->title(),
  25. ];
  26. }
  27. /**
  28. * Returns the post title.
  29. *
  30. * @return string
  31. */
  32. public function title()
  33. {
  34. if ($this->view->name() !== 'partials.page-header') {
  35. return get_the_title();
  36. }
  37. if (is_home()) {
  38. if ($home = get_option('page_for_posts', true)) {
  39. return get_the_title($home);
  40. }
  41. return __('Latest Posts', 'sage');
  42. }
  43. if (is_archive()) {
  44. return get_the_archive_title();
  45. }
  46. if (is_search()) {
  47. return sprintf(
  48. /* translators: %s is replaced with the search query */
  49. __('Search Results for %s', 'sage'),
  50. get_search_query()
  51. );
  52. }
  53. if (is_404()) {
  54. return __('Not Found', 'sage');
  55. }
  56. return get_the_title();
  57. }
  58. }