Randphibious Theme

This is not really as much of a theme as it is a modification/hack of our current theme, Amphibious by TemplatePocket. As Amphibious is released under GPL; I plan on forking it officially in the future. Until then, this page will act as a placeholder/info page.

The idea for this modification is based off the behavior of my previous theme and running with it. The previous theme, Bahari (or something), had a “random tagline” feature in it’s configuration. You enter what you want for taglines and it will display a random one under the site name. In fact the layout of that theme was largely similar to this one. I’ve liked random taglines going all the way back to 2002 when my first PHP powered site used one. Really liking this theme; I decided to put the effort in to modifying it for random taglines rather than find something else I liked with that built-in.

The random tagline was very quickly expanded to include the <title> element on the home-page; as well as an additional block of random text at the very bottom of the site.

functions.php

function randomtext() { 
    $lines = file("/var/www/pickmy/taglines.txt") ; 
    return $lines[array_rand($lines)] ; 
} 
function randomtail() { 
    $lines = file("/var/www/pickmy/tails.txt") ; 
    return $lines[array_rand($lines)] ; 
} 

These two functions added to functions.php are pretty simple. Each one reads from a textfile that contains each tag/quote on a newline; it then returns a random line of text.

header.php

<?php
// Fire tagline to global so it can be read by site-branding
global $description;
$description = randomtext();
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="profile" href="http://gmpg.org/xfn/11">
	<?php 
	// generates <title> with random tagline only on home page
	if(is_home()) : ?>
	<title> <?php echo $description; echo ' - pickmy.org ';?> </title>
	<?php endif; ?>
<?php wp_head(); ?>
</head>

In order to have the tagline used for <title> to match the one displayed on the site; we need to write it to a global variable; so we declare it global and write the output of randomtext(); to it. Further down the page, it checks to see if is_home() is true and render the randomized tagline in the <title>. Otherwise it does nothing, and WordPress will render it as part of wp_head().

inc/extras.php

/**
 * Designer Credits.
 *
 * @return void
 * 
 * hey...there you are. -j
 */
function amphibious_credits_designer() {
	// let's fire off a random tail.
	$tail = randomtail();
	// what is this mess? ok, add another &sdot and drop in %5$s so we don't fuck up the original theme too much.
	printf( '<div class="credits credits-designer">%1$s <a href="%2$s" title="TemplatePocket">TemplatePocket</a> <span>&sdot;</span> Tagline & Tail Randomizers by pickmy.org <span>&sdot;</span> %3$s <a href="%4$s" title="WordPress">WordPress</a> <span>&sdot;</span> %5$s </div>',
		esc_html__( 'Amphibious Theme by', 'amphibious' ),
		esc_url( 'https://templatepocket.com' ),
		esc_html__( 'Powered by', 'amphibious' ),
		esc_url( 'https://wordpress.org', 'amphibious' ),
		// it gets it's tail here.
		$tail
	);
}

So this one was “fun” to get working. The line of text at the bottom of the screen is technically part of the “credits”. Normally, it contains just a line of text and a link mentioning both TemplatePocket and WordPress. You can add your own “copyright” above it, but the text is a different size. I literally wanted to just slap my own text along side the original credits.

It was a little confusing figuring out this printf statement due to it being much wider than my page and confusing when word-wrapped. It did eventually click; so I fire the routine to generate a random tail and then slip it in to the printf statement.

template/site-branding.php

<?php
/**
 * The template for displaying site branding
 */
?>

<div class="site-branding-wrapper">
	<?php
	// Site Custom Logo
	if ( function_exists( 'the_custom_logo' ) ) {
		the_custom_logo();
	}
	?>

	<div class="site-branding">
		<?php if ( is_front_page() && is_home() ) : ?>
			<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
		<?php else : ?>
			<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
		<?php endif; ?>

		<?php
		// pull tagline from global variable
		global $description;
		if ( $description || is_customize_preview() ) :
		?>
		<p class="site-description">
			<?php 
			// now display it.
			echo esc_html( $description ); ?>
		</p>
		<?php endif; ?>
	</div>
</div><!-- .site-branding-wrapper -->

The text at the very top of the page is ultimately generated in the site-branding.php file. Largely all I did was remove references to where it was pulling the tagline to start with, and redirected it to the global variable we generate with the site header. This probably breaks the is_customize_preview() function; that is something I’ll look at in the future after I read up a but more on WordPress development and officially fork the theme. Even then, that would be an admin issue with previewing; so it won’t affect you at all and likely won’t affect me.

It should be noted that I’m not really planning on making a way to disable the quote randomizers; as that’s not the point of my mod. It is, in theory, possible to “disable” them by entering only a single entry in their text files; which I guess would be good if you wanted more of a semi-static display of text.

Site comments disabled. Please use Twitter.