Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Help Create Portfolio page with Taxonomies

Hi I need help... so far I have been able to create portfolio theme with the thing I have learn in Treehouse. I have use ACF and CPT UI to create field and custom post type for portfolio. but now I want to add taxonomies in Custom Post type UI and create category to show Portfolio category like: Graphic Design, Web, Photos etc... I am not sure which way is the best way to filter the portfolio category, therefore I have try to use taxonomies instead (please correct me if I am wrong) to add to custom port type. then I use plugin custom texonomies widget menu to show the taxonomies items. but the problems is when I click on each taxonomies items I get 404 error page. I already create taxonomy.php file to handle it but still show as 404 page. any suggestion?? here are some of my code

page-portfolio.php

<div class="row">
            <div class="col-md-12">

                <?php  

                    if(!function_exists('dynamic_sidebar') || !dynamic_sidebar( 'portfolio-menu' )) : ?>

                <?php endif;  ?>
            </div>
        </div>

        <div class="row">
                <?php 

                    $arg = array(
                        'post_type' => 'portfolio',
                        'posts_per_page' => 12
                    );
                    $the_query = new WP_Query($arg);
                ?>

                <?php if(have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>

                <div class="col-md-4">
                    <div class="port-box">
                        <img src="<?php the_field('port_images'); ?>" alt="" class="img-responsive">
                        <div class="port-info-b">
                            <p class="port-short-d">
                                <?php the_field('description'); ?>
                            </p>
                            <hr>
                            <a href="#" class="btn btn-primary"><i class="fa fa-search"></i> More Detail</a>
                        </div>
                        <div class="port-box-title">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        </div>
                    </div>
                </div>

                <?php $portfolio_count = $the_query->current_post + 1; ?>
                <?php if ( $portfolio_count % 3 == 0): ?>

                </div><div class="row">

                <?php endif; ?>


                <?php endwhile; endif; ?>

        <?php mts_paging_nav(); ?>

single-portfolio.php

<div class="row">
            <div class="col-md-12">

                <?php  

                    if(!function_exists('dynamic_sidebar') || !dynamic_sidebar( 'portfolio-menu' )) : ?>

                <?php endif;  ?>
            </div>
        </div>

        <div class="row">

            <div class="col-md-6">
                <div class="port-img-cover">
                    <img src="<?php the_field('port_images'); ?>" alt="port-detail-img" class="img-thumbnail">
                </div>
            </div> <!-- end column 6 -->
            <div class="col-md-6">
                <div class="port-info-detail">
                    <table class="table">
                        <tr>
                            <td width="30%" class="t-header">Project Name:</td>
                            <td width="70%"><?php the_title(); ?></td>
                        </tr>
                        <tr>
                            <td width="30%" class="t-header">Clients Name:</td>
                            <td width="70%"><?php the_field('client_name'); ?></td>
                        </tr>
                        <tr>
                            <td width="30%" class="t-header">Date:</td>
                            <td width="70%"><?php the_field('date'); ?></td>
                        </tr>
                        <tr>
                            <td width="30%" class="t-header">Type of Services:</td>
                            <td width="70%"><?php the_field('type_of_services'); ?></td>
                        </tr>
                        <tr>
                            <td width="30%" class="t-header">Project description:</td>
                            <td width="70%"><?php the_field('description'); ?></td>
                        </tr>
                    </table>
                </div>
            </div> <!-- end column 6 -->
        </div> <!-- end row -->
        <div class="row">
            <div class="col-md-12">
                <div class="panel">
                    <div class="panel-body ">
                        <?php the_field('port_detail'); ?>
                    </div>
                </div>
            </div>
        </div> <!-- end row -->

taxonomy.php

 <?php get_header(); ?>

<div class="container">

        <!-- Start breadcump  -->
        <?php
            if ( function_exists('custom_breadcrumb') ) {

                custom_breadcrumb();

            }
        ?>


        <div class="row">
                <div class="col-md-12">
                     <div class="title-item-wrapper">
                        <div class="title-item-gimmick left" style="width: 321px;"></div>
                        <h2 class="title-item-header"><span>Our Portfolio</span></h2>
                        <div class="title-item-gimmick right" style="width: 321px;"></div>
                        </div>
                </div>
        </div>
        <div class="row">
            <div class="col-md-12">

                <?php  

                    if(!function_exists('dynamic_sidebar') || !dynamic_sidebar( 'portfolio-menu' )) : ?>

                <?php endif;  ?>
            </div>
        </div>
        this is taxonomy page
        <div class="row">
                <?php 

                    // $arg = array(
                    //  'post_type' => 'portfolio'
                    // );
                    // $the_query = new WP_Query($arg);
                ?>

                <?php /*if(have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); */ ?>
                <?php   if (have_posts()) : while (have_posts()) : the_post();   ?>

                <div class="col-md-4">
                    <div class="port-box">
                        <img src="<?php the_field('port_images'); ?>" alt="" class="img-responsive">
                        <div class="port-info-b">
                            <p class="port-short-d">
                                <?php the_field('description'); ?>
                            </p>
                            <hr>
                            <a href="#" class="btn btn-primary"><i class="fa fa-search"></i> More Detail</a>
                        </div>
                        <div class="port-box-title">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        </div>
                    </div>
                </div>

                <?php $portfolio_count = $the_query->current_post + 1; ?>
                <?php if ( $portfolio_count % 3 == 0): ?>

                </div><div class="row">

                <?php endif; ?>


                <?php endwhile; endif; ?>

    </div>

<?php get_footer(); ?>

functions.php

add_action('init', 'cptui_register_my_taxes_portfolio');
    function cptui_register_my_taxes_portfolio() {
    register_taxonomy( 'portfolio', array (
        0 => 'portfolio',
    ),

    array( 'hierarchical' => true,
        'label' => 'Portfolio',
        'public' => true,
        'show_ui' => true,
        'query_var' => true,
        'show_admin_column' => false,
        'rewrite' => array( 'slug' => 'portfolio'),
        'labels' => array(
            'search_items' => 'Portfolio',
            'popular_items' => '',
            'all_items' => '',
            'parent_item' => '',
            'parent_item_colon' => '',
            'edit_item' => '',
            'update_item' => '',
            'add_new_item' => '',
            'new_item_name' => '',
            'separate_items_with_commas' => '',
            'add_or_remove_items' => '',
            'choose_from_most_used' => ''
        ),

    ) ); 
}

2 Answers

Shaker Advertising
Shaker Advertising
5,395 Points

This sounds stupid but have you tried resetting your permalink structure back to default, saving, then re-setting your permalinks back to what you previously had?

I've had this issue in the past, or something similar, and it turned out to be a conflict with my permalinks.

I finally fix the problems.. all good now.. :) yeah it was my mistake lol