質問

I'm using the portfolium-theme for Wordpress and I need your help.

I would like to show the portfolio category under the title on the frontpage (loop-portfolio). The Categories are with taxonomy but I can't figure it out.

my side

the loop-portfolio.php

 <?php if ( have_posts() ) : ?>
    <?php $i = 0; ?>
    <?php while ( have_posts() ) : the_post(); $i++; ?>
    <div class="post_home">
<div class="post_home2"></div>
        <a href="<?php the_permalink() ?>" class="thumb" title="<?php the_title(); ?>">

            <?php if (has_post_thumbnail()) : ?>
                <?php the_post_thumbnail(array(305,145)); ?>
            <?php else : ?>
                <img src="<?php bloginfo('template_url'); ?>/i/noimage.jpg" width="305" height="145" alt=""/>
            <?php endif; ?>
        </a>    
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> 




    </div>

    <?php if ($i % 6 == 0) echo '<div style="clear: both;"></div>'?>
    <?php endwhile; ?>
<?php endif; ?>

and the taxonomy.php

    <?php get_header(); ?>

<?php
    $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
    query_posts(array('post_type' => 'portfolio', 'works' => $term->slug, 'posts_per_page' => -1));
?>

<?php get_template_part('loop-portfolio');  // Loop template for portfolio (loop-portfolio.php) ?>

<?php get_footer(); ?>

the functions.php

    <?php

/*** Top navigation ***/

function register_menu() {
    register_nav_menu('Header', __('Header'));
}
add_action( 'init', 'register_menu' );

if ( !is_nav_menu('Header')) {
    $menu_id = wp_create_nav_menu('Header');
    wp_update_nav_menu_item($menu_id, 1);
}

class extended_walker extends Walker_Nav_Menu{
    function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {

        if ( !$element )
            return;

        $id_field = $this->db_fields['id'];

        //display this element
        if ( is_array( $args[0] ) )
            $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );

        //Adds the 'parent' class to the current item if it has children
        if( ! empty( $children_elements[$element->$id_field] ) )
            array_push($element->classes,'parent');

        $cb_args = array_merge( array(&$output, $element, $depth), $args);

        call_user_func_array(array(&$this, 'start_el'), $cb_args);

        $id = $element->$id_field;

        // descend only when the depth is right and there are childrens for this element
        if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {

            foreach( $children_elements[ $id ] as $child ){

                if ( !isset($newlevel) ) {
                    $newlevel = true;
                    //start the child delimiter
                    $cb_args = array_merge( array(&$output, $depth), $args);
                    call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
                }
                $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
            }
            unset( $children_elements[ $id ] );
        }

        if ( isset($newlevel) && $newlevel ){
            //end the child delimiter
            $cb_args = array_merge( array(&$output, $depth), $args);
            call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
        }

        //end this element
        $cb_args = array_merge( array(&$output, $element, $depth), $args);
        call_user_func_array(array(&$this, 'end_el'), $cb_args);
    }
}

/*** Commentlist ***/

function commentlist($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    ?>
    <li id="li-comment-<?php comment_ID() ?>">
        <div id="comment-<?php comment_ID(); ?>" <?php comment_class('comment_item clear'); ?>>
            <div class="comment_meta">Posted on <?php printf( __('%1$s'), get_comment_date()); ?> by <?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()) ?></div>
            <div class="comment_text"><?php comment_text() ?></div>
        </div>
<?php
}

/*** Custom Posts ***/

register_taxonomy(
    'works',
    'portfolio',
    array(
        'label' => __('Portfolio Categories'),
        'singular_label' => __('Portfolio Category'),
        'hierarchical' => true,
        'query_var' => true,
        'rewrite' => true,
        'show_in_nav_menus' => true,
    )
);

register_post_type(
    'portfolio',
    array(
        'label' => __('Portfolio'),
        'singular_label' => __('Work'),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => true,
        'query_var' => true,
        'show_in_nav_menus' => true,
        'menu_position' => 3,
        'taxonomies' => array('portfolio'),
        'supports' => array('title', 'editor', 'author', 'thumbnail', 'custom-fields'),
        '_builtin' => false, // It's a custom post type, not built in!
));

/*** Images ***/

add_theme_support('post-thumbnails');
update_option('thumbnail_size_w', 305);
update_option('thumbnail_size_h', 145);
update_option('large_size_w', 785);

/*** Misc ***/

function commentdata_fix($commentdata) {
    if ( $commentdata['comment_author_url'] == 'WWW') {
        $commentdata['comment_author_url'] = '';
    }
    if ($commentdata['comment_content'] == 'Write your comment') {
        $commentdata['comment_content'] = '';
    }
    return $commentdata;
}
add_filter('preprocess_comment','commentdata_fix');

function getTinyUrl($url) {
    $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
    return $tinyurl;
}

function get_blogurl() {
    if (get_option('show_on_front') == 'page' && get_option('page_for_posts') != 0) {
        $blogpage = get_page(get_option('page_for_posts'));
        echo $blogpage -> guid;
    } else {
        echo get_option('home');
    }
}

function catlist() { ?>
    <ul class="tags jsddm">
        <li>
            <a href="#">Blog categories</a>
            <ul class="taglist">
                <?php wp_list_categories('title_li=&hierarchical=0&'); ?>
            </ul>
        </li>
    </ul>
<?php
}

function n_posts_link_attributes(){
    return 'class="nextpostslink"';
}
function p_posts_link_attributes(){
    return 'class="previouspostslink"';
}
add_filter('next_posts_link_attributes', 'n_posts_link_attributes');
add_filter('previous_posts_link_attributes', 'p_posts_link_attributes');


?>
役に立ちましたか?

解決

Not sure if i understood what you want, but if you want a drop down menu for portfolio with all the taxonomies justuse the example in the WP codex for get term link Replace 'species' with your taxonomy (hope this is what you need, if not i'll try to help out) and thats about all you need to do

$terms = get_terms('species');
    echo '<ul>';
foreach ($terms as $term) {
    echo '<li><a href="'.get_term_link($term->slug, 'species').'">'.$term->name.'</a>
</li>';
}
echo '</ul>';

PS: if you're not sure what your terms bring back just use print_r($var_name); helps out a lot :)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top