Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Taxonomies and Getting all the posts, and include in Nav Menu WordPress

  • SOLVED

Hello,

I have a CPT called 'work' and attached to this CPT i have three Taxonomies:

1) Clients
2) Platforms
3) Project Types

My intended aim is to have all the posts within Clients shown on an Archive page of some sort.

I would like item to be displayed in a custom menu;

So the intended layout:

Work > Clients > XXX
Work > Platoforms > XXX
Work > Project Types > XXX

'XXX' being a term

Here is where i am at:

Functions:



add_action('init', 'create_work_clients');

function create_work_clients(){

$labels = array(
'name' => 'Clients',
'singular_name' => 'Clients',
'search_items' => 'Search Clients',
'popular_items' => 'Popular Clients',
'all_items' => 'All Clients',
'parent_item' => 'Parent Clients',
'edit_item' => 'Edit Clients',
'update_item' => 'Update Clients',
'add_new_item' => 'Add New Clients',
'new_item_name' => 'New Clients',
'separate_items_with_commas' => 'Separate Clients with commas',
'add_or_remove_items' => 'Add or remove Clients',
'choose_from_most_used' => 'Choose from most used Clients'
);

$args = array(
'label' => 'clients',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'work/clients', 'with_front' => false ),
'query_var' => true
);


register_taxonomy( 'clients', 'work', $args );
}



add_action('init', 'create_work_platforms');

function create_work_platforms(){
register_taxonomy('platforms','work',array(
'hierarchical' => true,
'label' => 'platforms'
));
}

add_action('init', 'create_work_projects');

function create_work_projects(){
register_taxonomy('project_types','work',array(
'hierarchical' => true,
'label' => 'project types'
));
}


function create_post_work(){




}


function create_post_type() {
register_post_type( 'team_members',
array(
'labels' => array(
'name' => __( 'The Team' ),
'singular_name' => __( 'The Team' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'team_members'),
'supports' => array('title','thumbnail','custom-fields')
)
);

register_post_type( 'work',
array(
'labels' => array(
'name' => __( 'Work' ),
'singular_name' => __( 'Work' )
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title','thumbnail','custom-fields','editor' ),
'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),
'has_archive' => true
)
);

register_post_type( 'slider',
array(
'labels' => array(
'name' => __( 'Slider' ),
'singular_name' => __( 'Slider' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'slider'),
'supports' => array('title','thumbnail','custom-fields')
)
);
}
add_action('init', 'create_post_type');


Template File



<?php
$counter = 0;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'post_type' => 'work',
'taxonomy' => 'clients',
'paged' => $paged,

'posts_per_page' => $post_per_page,
'order' => 'ASC'
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>


<?php $catTags = "";
$catClass = "";
$singleTag = "";
?>
<?php
// Post Terms
$terms = get_the_terms( $post->ID, 'clients' );
if ( $terms && ! is_wp_error( $terms ) ) :
$clients_list = array();
foreach ( $terms as $term ) {
$clients_list[] = $term->name;
}
$clients = join( ", ", $clients_list );
$clients_class = join( " ", $clients_list );
$catTags .= "$clients, ";
$catClass .= "$clients_class ";
$singleTag .= $clients_class;
endif;

// Post Terms
$terms = get_the_terms( $post->ID, 'platforms' );
if ( $terms && ! is_wp_error( $terms ) ) :
$platform_list = array();
foreach ( $terms as $term ) {
$platform_list[] = $term->name;
}
$platforms = join( ", ", $platform_list );
$platforms_class = join( " ", $platform_list );
$catTags .= "$platforms, ";
$catClass .= "$platforms_class ";
endif;

// Post Terms
$terms = get_the_terms( $post->ID, 'project_types' );
if ( $terms && ! is_wp_error( $terms ) ) :
$project_types = array();
foreach ( $terms as $term ) {
$project_types[] = $term->name;
}
$projectTypes = join( ", ", $project_types );
$projectTypes_class = join( " ", $project_types );
$catTags .= "$platforms, ";
$catClass .= "$projectTypes_class ";
endif;
?>

<?php $work_feature = get_post_meta($post->ID, 'work_feature', $single = true); ?>

<div class="fourcol project post<?php echo $counter + 1 ?> <?php echo $catClass; ?> <?php echo $work_feature; ?>">
<?php $counter = $counter + 1; ?>

<?php if ( has_post_thumbnail()) { ?>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail(array(352,198), array('title' => trim(strip_tags( $attachment->post_title)), ));?></a>
<?php } else {?>
<a href="<?php the_permalink();?>"><img src="<?php bloginfo('template_directory');?>/images/352x198.jpg" alt="<?php the_title(); ?>" /></a>
<?php } ?>


<a href="<?php the_permalink(); ?>"><h3><?php the_title();?></h3></a>
<h3 class="singleTag"><?php echo $singleTag; ?></h3>
<?php $project_description = get_post_meta($post->ID, 'project_description', $single = true); ?>
<p><?php echo $project_description; ?></p>
<em><?php $string = rtrim($catTags, ', '); print_r($string); ?></em>


</div>

<?php endwhile; ?>

<?php endif; $wp_query = $temp; //reset back to original query ?>
<?php wp_reset_query();?>



So just to confirm:

I would like to show all the posts of a queried taxonomy: e.g. 'clients' and have that page (archive) included in the nav menu (wp 3.0+)

So if the user went to example.com/work/clients/ they would land on the index of that taxonomy.



Thanks

Answers (4)

2011-10-03

Luis Abarca answers:

OK, I start working on it


xavier comments:

thanks, i look forward to your solution


Luis Abarca comments:

As you are using work as post type and as rewrite rule, work/clients, the best option is to create a page with that path, and create 2 page template, first 'page-work.php' to show the work post type archive and 'page-clients.php' to show all the taxnomies in clients custom taxonomy, i make a mod on your current code and converted to a plugin


<?php
/*
Plugin Name: Test Pilot
*/


register_activation_hook(__FILE__, 'work_cpt_activate');
register_deactivation_hook(__FILE__, 'work_cpt_deactivate');

function jab_hotel_activate()
{
// init custom types
create_work_custom_types();

// only called on plugin activation for better performance
flush_rewrite_rules();
}

function jab_hotel_deactivate()
{
flush_rewrite_rules();
}


add_action('init', 'create_work_custom_types');

function create_work_custom_types()
{
create_post_type();

create_work_clients();
create_work_platforms();
create_work_projects();
}

function create_work_clients()
{
$labels = array(
'name' => 'Clients',
'singular_name' => 'Clients',
'search_items' => 'Search Clients',
'popular_items' => 'Popular Clients',
'all_items' => 'All Clients',
'parent_item' => 'Parent Clients',
'edit_item' => 'Edit Clients',
'update_item' => 'Update Clients',
'add_new_item' => 'Add New Clients',
'new_item_name' => 'New Clients',
'separate_items_with_commas' => 'Separate Clients with commas',
'add_or_remove_items' => 'Add or remove Clients',
'choose_from_most_used' => 'Choose from most used Clients'
);

$args = array(
'label' => 'clients',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array(
'slug' => 'work/clients',
'with_front' => false
),
'query_var' => true
);

register_taxonomy( 'clients', 'work', $args );
}

function create_work_platforms()
{
register_taxonomy('platforms', 'work', array(
'hierarchical' => true,
'label' => 'platforms'
));
}

function create_work_projects()
{
register_taxonomy('project_types','work',array(
'hierarchical' => true,
'label' => 'project types'
));
}

function create_post_work()
{
}

function create_post_type()
{
register_post_type( 'team_members', array('labels' => array(
'name' => __( 'The Team' ),
'singular_name' => __( 'The Team' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'team_members'),
'supports' => array('title', 'thumbnail','custom-fields')
)
);

register_post_type( 'work', array(
'labels' => array(
'name' => __( 'Work' ),
'singular_name' => __( 'Work' )
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title','thumbnail','custom-fields','editor' ),
'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),
'has_archive' => true)
);

register_post_type( 'slider', array(
'labels' => array(
'name' => __( 'Slider' ),
'singular_name' => __( 'Slider' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'slider'),
'supports' => array('title','thumbnail','custom-fields')
)
);
}


Luis Abarca comments:

create a page with 'work' slug

create 'page-work.php' on your theme, notice: im using the tweenty eleven theme archive file


<?php
/**
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
<strong>
query_posts('post_type=work');
</strong>
get_header(); ?>

<section id="primary">
<div id="content" role="main">

<?php if ( have_posts() ) : ?>

<header class="page-header">
<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( 'Daily Archives: %s', 'twentyeleven' ), '<span>' . get_the_date() . '</span>' ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'F Y' ) . '</span>' ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'Y' ) . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Blog Archives', 'twentyeleven' ); ?>
<?php endif; ?>
</h1>
</header>

<?php twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>

<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>

<?php endwhile; ?>

<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>

<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->

<?php endif; ?>

</div><!-- #content -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>


Luis Abarca comments:

Sorry, the plugin has an error, try this one


<?php
/*
Plugin Name: Test Pilot
*/
<strong>
register_activation_hook(__FILE__, 'work_cpt_activate');
register_deactivation_hook(__FILE__, 'work_cpt_deactivate');

function work_cpt_activate()
{
// init custom types
create_work_custom_types();

// only called on plugin activation for better performance
flush_rewrite_rules();
}

function work_cpt_deactivate()
{
flush_rewrite_rules();
}
</strong>




add_action('init', 'create_work_custom_types');



function create_work_custom_types()

{

create_post_type();



create_work_clients();

create_work_platforms();

create_work_projects();

}



function create_work_clients()

{

$labels = array(

'name' => 'Clients',

'singular_name' => 'Clients',

'search_items' => 'Search Clients',

'popular_items' => 'Popular Clients',

'all_items' => 'All Clients',

'parent_item' => 'Parent Clients',

'edit_item' => 'Edit Clients',

'update_item' => 'Update Clients',

'add_new_item' => 'Add New Clients',

'new_item_name' => 'New Clients',

'separate_items_with_commas' => 'Separate Clients with commas',

'add_or_remove_items' => 'Add or remove Clients',

'choose_from_most_used' => 'Choose from most used Clients'

);



$args = array(

'label' => 'clients',

'labels' => $labels,

'public' => true,

'hierarchical' => true,

'show_ui' => true,

'show_in_nav_menus' => true,

'args' => array( 'orderby' => 'term_order' ),

'rewrite' => array(

'slug' => 'work/clients',

'with_front' => false

),

'query_var' => true

);



register_taxonomy( 'clients', 'work', $args );

}



function create_work_platforms()

{

register_taxonomy('platforms', 'work', array(

'hierarchical' => true,

'label' => 'platforms'

));

}



function create_work_projects()

{

register_taxonomy('project_types','work',array(

'hierarchical' => true,

'label' => 'project types'

));

}



function create_post_work()

{

}



function create_post_type()

{

register_post_type( 'team_members', array('labels' => array(

'name' => __( 'The Team' ),

'singular_name' => __( 'The Team' )

),

'public' => true,

'menu_position' => 6,

'rewrite' => array('slug' => 'team_members'),

'supports' => array('title', 'thumbnail','custom-fields')

)

);



register_post_type( 'work', array(

'labels' => array(

'name' => __( 'Work' ),

'singular_name' => __( 'Work' )

),

'public' => true,

'show_ui' => true,

'show_in_menu' => true,

'supports' => array( 'title','thumbnail','custom-fields','editor' ),

'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),

'has_archive' => true)

);



register_post_type( 'slider', array(

'labels' => array(

'name' => __( 'Slider' ),

'singular_name' => __( 'Slider' )

),

'public' => true,

'menu_position' => 6,

'rewrite' => array('slug' => 'slider'),

'supports' => array('title','thumbnail','custom-fields')

)

);

}


Luis Abarca comments:

OK, its working now,

ill paste it here with the corrections

plugin to CPT


<?php
/*
Plugin Name: Test Pilot
*/

register_activation_hook(__FILE__, 'work_cpt_activate');
register_deactivation_hook(__FILE__, 'work_cpt_deactivate');

function work_cpt_activate()
{
// init custom types
create_work_custom_types();

// only called on plugin activation for better performance
flush_rewrite_rules();
}

function work_cpt_deactivate()
{
flush_rewrite_rules();
}


add_action('init', 'create_work_custom_types');

function create_work_custom_types()
{
create_post_type();

create_work_clients();
create_work_platforms();
create_work_projects();

work_add_rewrites();
}

function work_add_rewrites()
{

add_rewrite_rule("work/clients/([^/]+)/?$", 'index.php?clients=$matches[1]', 'top');
add_rewrite_rule("work/clients/([^/]+)/page/([0-9]{1,})/?$", 'index.php?clients=$matches[1]&paged=$matches[2]', 'bottom');


}


function create_work_clients()
{
$labels = array(
'name' => 'Clients',
'singular_name' => 'Clients',
'search_items' => 'Search Clients',
'popular_items' => 'Popular Clients',
'all_items' => 'All Clients',
'parent_item' => 'Parent Clients',
'edit_item' => 'Edit Clients',
'update_item' => 'Update Clients',
'add_new_item' => 'Add New Clients',
'new_item_name' => 'New Clients',
'separate_items_with_commas' => 'Separate Clients with commas',
'add_or_remove_items' => 'Add or remove Clients',
'choose_from_most_used' => 'Choose from most used Clients'
);

$args = array(
'label' => 'clients',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array(
'slug' => 'clients',
'with_front' => false
),
'query_var' => true
);

register_taxonomy( 'clients', 'work', $args );
}

function create_work_platforms()
{
register_taxonomy('platforms', 'work', array(
'hierarchical' => true,
'label' => 'platforms'
));
}

function create_work_projects()
{
register_taxonomy('project_types','work',array(
'hierarchical' => true,
'label' => 'project types'
));
}

function create_post_work()
{
}

function create_post_type()
{
register_post_type( 'team_members', array('labels' => array(
'name' => __( 'The Team' ),
'singular_name' => __( 'The Team' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'team_members'),
'supports' => array('title', 'thumbnail','custom-fields')
)
);

register_post_type( 'work', array(
'labels' => array(
'name' => __( 'Work' ),
'singular_name' => __( 'Work' )
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title','thumbnail','custom-fields','editor' ),
'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),
'has_archive' => true)
);

register_post_type( 'slider', array(
'labels' => array(
'name' => __( 'Slider' ),
'singular_name' => __( 'Slider' )
),
'public' => true,
'menu_position' => 6,
'rewrite' => array('slug' => 'slider'),
'supports' => array('title','thumbnail','custom-fields')
)
);
}


Luis Abarca comments:

1.- Create a new page with the 'work' slug
2.- Create a new file in your template page-work.php
3.- Paste this code


<?php
/*
Template Name: Work Archive
*/

query_posts('post_type=work');

get_header(); ?>
<section id="primary">
<div id="content" role="main">

<?php if ( have_posts() ) : ?>

<header class="page-header">
<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( 'Daily Archives: %s', 'twentyeleven' ), '<span>' . get_the_date() . '</span>' ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'F Y' ) . '</span>' ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'Y' ) . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Blog Archives', 'twentyeleven' ); ?>
<?php endif; ?>
</h1>
</header>

<?php twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>

<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>

<?php endwhile; ?>

<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>

<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->

<?php endif; ?>

</div><!-- #content -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>



Luis Abarca comments:

1. -Create a new page in your blog with 'clients' slug and the 'work' as parent
2.- Create a new file in your template, page-clients.php
3.- copy and paste
4.- repeat for platforms and project types, but change the taxonomy


<?php
/*
Template Name: Clients Archive
*/

// terms in clients
<strong>$taxonomy = 'clients';</strong>
$terms = get_terms($taxonomy);


$terms_slug = array();

if ( count($terms) > 0 ){
foreach ( $terms as $term ) {
$terms_slug[] = $term->slug;
}
}

$args = array(
'paged' => get_query_var('page'),
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $terms_slug )
)
);

query_posts( $args );

get_header(); ?>

<section id="primary">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>

<header class="page-header">
<h1 class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( 'Daily Archives: %s', 'twentyeleven' ), '<span>' . get_the_date() . '</span>' ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'F Y' ) . '</span>' ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'Y' ) . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Blog Archives', 'twentyeleven' ); ?>
<?php endif; ?>
</h1>
</header>

<?php twentyeleven_content_nav( 'nav-above' ); ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>

<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>

<?php endwhile; ?>

<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>

<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->

<?php endif; ?>

</div><!-- #content -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>


Luis Abarca comments:

Is working here http://dev.justoalblanco.com/work/clients/, but notice that im using the default theme.

If you need any help or issue let me know!


Luis Abarca comments:

For menus, just add a custom item with a url like /work/clients

I.e: http://dev.justoalblanco.com/


xavier comments:

This is exactly what i was after, needs some tweaking for my individual requirements but it seems to do the job, i can now just add the pages to the nav_menu.

I think this is the right solution but i wont award the prize just yet just-incase i encounter some issues.

Thanks


xavier comments:

Issue #1

The pages my custom menu do not register properly, they do not have an active class assigned to them, so i can not create custom CSS to show that the 'clients' archive is the active page.

Please resolve.


xavier comments:


<div id="blurb" class="row filters">
<div class="threecol border">
<h1>Work</h1>
</div>
<?php wp_nav_menu( array( 'theme_location' => 'filters', 'menu_class' => 'filters', 'fallback_cb' => '') ); ?>

<div class="list_items row">

<div class="list_clients row" style="display:none">
<div class="threecol" style="height:120px;">&nbsp;</div>
<?php
//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$taxonomy = 'clients';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';

$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>
</div>

</div>
</div>



Here is the code associated to the menu, specifically this is the line that loads in my custom menu <?php wp_nav_menu( array( 'theme_location' => 'filters', 'menu_class' => 'filters', 'fallback_cb' => '') ); ?>


Luis Abarca comments:

Can you PM the page url or login details to check this issue ??

2011-10-03

Elliott Richmond answers:

This is relatively easy, you just great a post tag for each term, then create a menu in appearance > menus. Just make sure you have 'post tags' checked in the Screen Options (top right hand corner of the screen) you can then just create the menu you want that calls the relevant archive template.

If you need further help dm me ;-)

2011-10-03

Abdessamad Idrissi answers:

To show posts from a specific taxonomy add the following in your "taxonomy.php" file, :

$args = array(
'posts_per_page' => 20,
'paged' => $paged,
'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => get_query_var('taxonomy'),
'field' => 'slug',
'terms' => get_query_var('term')
)
)
);

query_posts( $args );


Abdessamad Idrissi comments:

I verified the way you created taxonomies and found you can do better by creating a post type called "work" with slug "projects" which is linked to a taxonomy that plays a role of parent category with name "works_cat" and slug "work".

Then you can create in through the dashboard the three sub categories (or more): "Clients", "Platforms" and "Project Types".

This way you can access all the projects in for example "clients" using the link : example.com/work/clients/

Easy eh? Here is the complete code to paste/replace in

Functions:

$labels = array(
'name' => 'Works',
'singular_name' => 'Work',
);

$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),
'query_var' => true,
'has_archive' => true,
'supports' => array( 'title','thumbnail','custom-fields','editor' )
);

register_post_type('work', $args);

// register the new ad category taxonomy
register_taxonomy( 'works_cat',
array('work'),
array('hierarchical' => true,
'labels' => array(
'name' => 'Work Categories',
'singular_name' => 'Work Category',
'search_items' => 'Search Work Categories',
'all_items' => 'All Work Categories',
'parent_item' => 'Parent Work Category',
'parent_item_colon' => 'Parent Work Category:',
'edit_item' => 'Edit Work Category',
'update_item' => 'Update Work Category',
'add_new_item' => 'Workd New Work Category',
'new_item_name' => 'New Work Category Name'
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'work', 'with_front' => false )
)
);


taxonomy.php


$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
'posts_per_page' => 20,
'paged' => $paged,
'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => get_query_var('taxonomy'),
'field' => 'slug',
'terms' => get_query_var('term')
)
)
);

query_posts( $args );

if(have_posts()) : ?>

<?php while(have_posts()) : the_post(); ?>

<?php get_template_part( 'loop', 'item' ); ?>

<?php endwhile; ?>

<?php else: ?>

<h2>nothing dfound</p>

<?php endif; ?>


Abdessamad Idrissi comments:

You can pm me your paypal and I'll guide you step by step to fix it :)


Abdessamad Idrissi comments:

I mean you Skype ;)

2011-10-05

jevusi answers:


<?php

$counter = 0;

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$post_per_page = -1; // -1 shows all posts

$do_not_show_stickies = 1; // 0 to show stickies

$args=array(

'post_type' => 'work',

'taxonomy' => 'clients',

'paged' => $paged,



'posts_per_page' => $post_per_page,

'order' => 'ASC'

);

$temp = $wp_query; // assign orginal query to temp variable for later use

$wp_query = null;

$wp_query = new WP_Query($args);

if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>





<?php $catTags = "";

$catClass = "";

$singleTag = "";

?>

<?php

// Post Terms

$terms = get_the_terms( $post->ID, 'clients' );

if ( $terms && ! is_wp_error( $terms ) ) :

$clients_list = array();

foreach ( $terms as $term ) {

$clients_list[] = $term->name;

}

$clients = join( ", ", $clients_list );

$clients_class = join( " ", $clients_list );

$catTags .= "$clients, ";

$catClass .= "$clients_class ";

$singleTag .= $clients_class;

endif;



// Post Terms

$terms = get_the_terms( $post->ID, 'platforms' );

if ( $terms && ! is_wp_error( $terms ) ) :

$platform_list = array();

foreach ( $terms as $term ) {

$platform_list[] = $term->name;

}

$platforms = join( ", ", $platform_list );

$platforms_class = join( " ", $platform_list );

$catTags .= "$platforms, ";

$catClass .= "$platforms_class ";

endif;



// Post Terms

$terms = get_the_terms( $post->ID, 'project_types' );

if ( $terms && ! is_wp_error( $terms ) ) :

$project_types = array();

foreach ( $terms as $term ) {

$project_types[] = $term->name;

}

$projectTypes = join( ", ", $project_types );

$projectTypes_class = join( " ", $project_types );

$catTags .= "$platforms, ";

$catClass .= "$projectTypes_class ";

endif;

?>



<?php $work_feature = get_post_meta($post->ID, 'work_feature', $single = true); ?>



<div class="fourcol project post<?php echo $counter + 1 ?> <?php echo $catClass; ?> <?php echo $work_feature; ?>">

<?php $counter = $counter + 1; ?>



<?php if ( has_post_thumbnail()) { ?>

<a href="<?php the_permalink();?>"><?php the_post_thumbnail(array(352,198), array('title' => trim(strip_tags( $attachment->post_title)), ));?></a>

<?php } else {?>

<a href="<?php the_permalink();?>"><img src="<?php bloginfo('template_directory');?>/images/352x198.jpg" alt="<?php the_title(); ?>" /></a>

<?php } ?>





<a href="<?php the_permalink(); ?>"><h3><?php the_title();?></h3></a>

<h3 class="singleTag"><?php echo $singleTag; ?></h3>

<?php $project_description = get_post_meta($post->ID, 'project_description', $single = true); ?>

<p><?php echo $project_description; ?></p>

<?php $string = rtrim($catTags, ', '); print_r($string); ?>





</div>



<?php endwhile; ?>



<?php endif; $wp_query = $temp; //reset back to original query ?>

<?php wp_reset_query();?>