Skip to content

Instantly share code, notes, and snippets.

@fahdi
Created November 30, 2013 01:39
Show Gist options
  • Save fahdi/7714336 to your computer and use it in GitHub Desktop.
Save fahdi/7714336 to your computer and use it in GitHub Desktop.
This gist is a solution to the problem at http://wpquestions.com/question/show/id/9039
<?php
/**
* The template for displaying Archive pages
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
* new template file for each specific one. For example, Twenty Twelve already
* has tag.php for Tag archives, category.php for Category archives, and
* author.php for Author archives.
*
* @link http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header();
?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/* Include the post format-specific template for the content. If you want to
* this in a child theme then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$term_id = $term->term_id;
//echo $term_id;
$t_id = $term_id;
$term_meta = get_option( "taxonomy_term_$t_id" );
/*
echo "<pre>";
print_r( $term_meta);
echo "</pre>";
*/
extract($term_meta);
echo "<br/>".$photo;
echo "<br/>".$name;
echo "<br/>".$aka;
echo "<br/>".$birth;
echo "<br/>".$birth_place;
echo "<br/>".$death;
echo "<br/>".$star_sign;
echo "<br/>".$hit_movies;
echo "<br/>".$hit_songs;
echo "<br/>".$bio;
endwhile;
twentytwelve_content_nav( 'nav-below' );
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
// custom author taxonomy
add_action( 'init', 'register_taxonomy_authors' );
function register_taxonomy_authors() {
$labels = array(
'name' => _x( 'Authors', 'authors' ),
'singular_name' => _x( 'Author', 'authors' ),
'search_items' => _x( 'Search Authors', 'authors' ),
'popular_items' => _x( 'Popular Authors', 'authors' ),
'all_items' => _x( 'All Authors', 'authors' ),
'parent_item' => _x( 'Parent Author', 'authors' ),
'parent_item_colon' => _x( 'Parent Author:', 'authors' ),
'edit_item' => _x( 'Edit Author', 'authors' ),
'update_item' => _x( 'Update Author', 'authors' ),
'add_new_item' => _x( 'Add New Author', 'authors' ),
'new_item_name' => _x( 'New Author', 'authors' ),
'separate_items_with_commas' => _x( 'Separate authors with commas', 'authors' ),
'add_or_remove_items' => _x( 'Add or remove Authors', 'authors' ),
'choose_from_most_used' => _x( 'Choose from most used Authors', 'authors' ),
'menu_name' => _x( 'Authors', 'authors' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'show_admin_column' => false,
'hierarchical' => false,
'rewrite' => true,
'query_var' => true
);
register_taxonomy( 'authors', array('post'), $args );
}
// A callback function to add a custom field to our "authors" taxonomy
function authors_taxonomy_custom_fields($tag) {
// Check for existing taxonomy meta for the term you're editing
$t_id = $tag->term_id; // Get the ID of the term you're editing
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="photo"><?php _e('Photo'); ?></label>
</th>
<td>
<input type="text" name="term_meta[photo]" id="term_meta[photo]" size="25" style="width:60%;" value="<?php echo $term_meta['photo'] ? $term_meta['photo'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Photo URL'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="name"><?php _e('Name'); ?></label>
</th>
<td>
<input type="text" name="term_meta[name]" id="term_meta[name]" size="25" style="width:60%;" value="<?php echo $term_meta['name'] ? $term_meta['name'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Birth Name'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="aka"><?php _e('AKA'); ?></label>
</th>
<td>
<input type="text" name="term_meta[aka]" id="term_meta[aka]" size="25" style="width:60%;" value="<?php echo $term_meta['aka'] ? $term_meta['aka'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Nickname'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="birth"><?php _e('Birth'); ?></label>
</th>
<td>
<input type="text" name="term_meta[birth]" id="term_meta[birth]" size="25" style="width:60%;" value="<?php echo $term_meta['birth'] ? $term_meta['birth'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Birth Date'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="birth_place"><?php _e('Birth Place'); ?></label>
</th>
<td>
<input type="text" name="term_meta[birth_place]" id="term_meta[birth_place]" size="25" style="width:60%;" value="<?php echo $term_meta['birth_place'] ? $term_meta['birth_place'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Birth Place'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="death"><?php _e('Death'); ?></label>
</th>
<td>
<input type="text" name="term_meta[death]" id="term_meta[death]" size="25" style="width:60%;" value="<?php echo $term_meta['death'] ? $term_meta['death'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Death Date'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="star_sign"><?php _e('Star Sign'); ?></label>
</th>
<td>
<input type="text" name="term_meta[star_sign]" id="term_meta[star_sign]" size="25" style="width:60%;" value="<?php echo $term_meta['star_sign'] ? $term_meta['star_sign'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Zodiac'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="hit_movies"><?php _e('Hit Movies'); ?></label>
</th>
<td>
<input type="text" name="term_meta[hit_movies]" id="term_meta[hit_movies]" size="25" style="width:60%;" value="<?php echo $term_meta['hit_movies'] ? $term_meta['hit_movies'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Hit Movies'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="hit_songs"><?php _e('Hit Songs'); ?></label>
</th>
<td>
<input type="text" name="term_meta[hit_songs]" id="term_meta[hit_songs]" size="25" style="width:60%;" value="<?php echo $term_meta['hit_songs'] ? $term_meta['hit_songs'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Hit Songs'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="bio"><?php _e('Bio'); ?></label>
</th>
<td>
<input type="text" name="term_meta[bio]" id="term_meta[bio]" size="25" style="width:100%; height:200px;" value="<?php echo $term_meta['bio'] ? $term_meta['bio'] : ''; ?>"><br />
<span class="description"><?php _e('The Author\'s Bio Description'); ?></span>
</td>
</tr>
<?php
}
// A callback function to save our extra taxonomy field(s)
function save_taxonomy_custom_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_term_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ){
if ( isset( $_POST['term_meta'][$key] ) ){
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
//save the option array
update_option( "taxonomy_term_$t_id", $term_meta );
}
}
// Add the fields to the "authors" taxonomy, using our callback function
add_action( 'authors_edit_form_fields', 'authors_taxonomy_custom_fields', 10, 2 );
// Save the changes made on the "authors" taxonomy, using our callback function
add_action( 'edited_authors', 'save_taxonomy_custom_fields', 10, 2 );
add_action('wp_head', 'show_template');
function show_template() {
global $template;
print_r($template);
}
?>
<?php
// Post Loop code above, mid loop
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$term_id = $term->term_id;
//echo $term_id;
$t_id = $term_id;
$term_meta = get_option( "taxonomy_term_$t_id" );
/*
echo "<pre>";
print_r( $term_meta);
echo "</pre>";
*/
extract($term_meta);
echo "<br/>".$photo;
echo "<br/>".$name;
echo "<br/>".$aka;
echo "<br/>".$birth;
echo "<br/>".$birth_place;
echo "<br/>".$death;
echo "<br/>".$star_sign;
echo "<br/>".$hit_movies;
echo "<br/>".$hit_songs;
echo "<br/>".$bio;
// Post Loop code below, mid loop
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment