This is the /app/Controllers/App.php file that we have:
<?php
namespace App\Controllers;
use Sober\Controller\Controller;
class App extends Controller
{
public function siteName()
{
return get_bloginfo('name');
}
public static function title()
{
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
return get_the_title($home);
}
return __('Latest Posts', 'sage');
}
if (is_archive()) {
return get_the_archive_title();
}
if (is_search()) {
return sprintf(__('Search Results for %s', 'sage'), get_search_query());
}
if (is_404()) {
return __('Not Found', 'sage');
}
return get_the_title();
}
public static function siteLogo()
{
$logo = get_theme_mod( 'to4_theme_logo' );
if( $logo ) {
return wp_get_attachment_image( $logo, 'thumbnail' );
}
return '<span class="site-title">' . get_bloginfo( 'name' ) . '</span>';
}
public static function primaryNavigation()
{
if (has_nav_menu('primary_navigation')) {
return wp_nav_menu([
'container' => false,
'menu' => __( 'Primary Navigation', 'sage' ),
'menu_class' => 'dropdown vertical medium-horizontal menu',
'theme_location' => 'primary_navigation',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
// Recommend setting this to false, but if you need a fallback....
'fallback_cb' => false,
'walker' => new \truthout4_f6_menu_walker()
]);
}
return '<span class="">Please select a Primary Menu</span>';
}
public static function secondaryNavigation()
{
if (has_nav_menu('secondary_navigation'))
{
return wp_nav_menu([
'container' => false,
'menu' => __( 'Secondary Navigation', 'sage' ),
'menu_class' => 'dropdown vertical medium-horizontal menu',
'theme_location' => 'secondary_navigation',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
// Recommend setting this to false, but if you need a fallback....
'fallback_cb' => false,
'walker' => new \truthout4_f6_menu_walker()
]);
}
return '<span class="">Please select a Secondary Menu</span>';
}
/**
* Setup sitewide variables for featured articles.
* @return $data key => value array for use in blade templates.
*/
public function featuredArticles()
{
$data = [];
$featured_articles = get_option( 'options_to4_featured_posts' );
foreach ($featured_articles as $article) {
$terms = get_the_terms( $article, 'section' );
if ( $terms && !is_wp_error( $terms ) ) {
$term_array = array_pop($terms);
$term = $term_array->name;
} else {
$term = '';
}
$author_names = [];
// Retrieve article authors post meta from each $article post
$authors = get_post_meta( $article, 'to4_related_authors', true );
// If authors exist and is not wp_error...
if ( $authors && !is_wp_error( $authors ) ) {
// Iterate through array and retrieve author name, populate array with names.
foreach( $authors as $author ) {
$author_name = get_the_title($author);
array_push($author_names, $author_name);
}
// Convert array values into string for use in our array object below.
$author_names = implode(', ', $author_names);
}
$this_post = (object) [
'medium_thumb' => get_the_post_thumbnail($article, 'sd_thumbnail', ['class' => '']),
'large_thumb' => get_the_post_thumbnail($article, 'sd_medium', ['class' => '']),
'permalink' => get_the_permalink($article),
'title' => get_the_title($article),
'short_title' => mb_strimwidth( get_the_title($article), 0, 40, '…' ),
'excerpt' => get_the_excerpt($article),
'term' => $term,
'date' => get_the_date('F j, Y', $article),
'authors' => $author_names
];
array_push($data, $this_post);
}
// Only retrieve the first 4 posts for the homepage
if( is_front_page() ) {
$data = array_slice($data, 0, 4);
}
return $data;
}
}
Have I formatted it incorrectly somewhere?
And in header.blade.php
I’m referencing the static methods like this:
Controllers\App::siteLogo()