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

loop nav for custom post type WordPress

  • SOLVED

I am using Foxyshop, which is a plugin that works with foxycart. The problem is not with either of these though, but the loop nav and custom post types. [[LINK href="http://www.oliverfabrics.com/products/test-fabric-for-inventory-level/"]][[/LINK]] Custom post link. [[LINK href="http://www.oliverfabrics.com/2010/08/dragonfly-velvet/"]][[/LINK]] Regular post link.
<div class="loop-nav">

<?php previous_post_link( '<div class="previous">' . __( '%link', hybrid_get_textdomain() ) . '</div>', '%title', TRUE ); ?>
<?php next_post_link( '<div class="next">' . __( '%link', hybrid_get_textdomain() ) . '</div>', '%title', TRUE ); ?>
</div>

This works for regular posts. If set to "FALSE", it works with the cpt's also. Thing is, I always use "TRUE" because I like the post to show previous and next only within the category, as opposed to showing all the posts. Below is the single page template code for the entire page.
<?php get_header(); ?>

<?php
//Hide page content if plugin is disabled
if (function_exists('foxyshop_insert_foxycart_files')) {
?>
<div id="foxyshop_container">
<?php
foxyshop_include('header');
while (have_posts()) : the_post();

?>
<?php

//Initialize Product
global $product;
$product = foxyshop_setup_product();

//This is for testing to see what is included in the $product array
//print_r($product);

//Initialize Form
foxyshop_start_form();

//Write Breadcrumbs
foxyshop_breadcrumbs(" / ", "/ Back to Products");

echo '<h1 class="single-title entry-title">' . apply_filters('the_title', $product['name']) . '</h1>';
//Main Product Information Area
echo '<div class="foxyshop_product_info">';

//Show a sale tag if the product is on sale
if (foxyshop_is_on_sale()) echo '<p>SALE!</p>';

//Product Is New Tag (number of days since added)
//if (foxyshop_is_product_new(14)) echo '<p>NEW!</p>';

//Main Product Description
echo '<div class="entry-content">';
echo $product['description'];
echo do_shortcode('[custom_share_icons]');
echo '</div>';
echo do_shortcode('[details]');
echo'<div class="clear"></div>';
//Show Variations (showQuantity: 0 = Do Not Show Qty, 1 = Show Before Variations, 2 = Show Below Variations)
foxyshop_product_variations(2);


//(style) clear floats before the submit button

//Add To Cart Button
echo '<button type="submit" name="x:productsubmit" id="productsubmit" class="foxyshop_button">Add To Cart</button>';

//Shows the Price (includes sale price if applicable)
echo '<div id="foxyshop_main_price">';
foxyshop_price();
echo '</div>';

//Check Inventory Levels and Display Status (last variable allows ordering of out of stock items)
foxyshop_inventory_management("There are only %c item%s left in stock!", "sorry, item is not in stock.", false);

//Shows any related products
foxyshop_related_products("Related Products");


//Ends the form
echo '</div>';
echo '</form>';
//Show the Main Image and Slideshow if Available
echo '<div id="wrap-left"><div id="main-image">';
get_the_image( array( 'custom_key' => array( 'medium' ), 'link_to_post' => false, 'default_size' => 'medium', 'width' => '', 'height' => '270' ) );
echo '</div><ul id="mycarousel" class="jcarousel-skin-tango">';
my_attachment_galleries(0, 'mycustom-thumbnail-100', 'alt="' . $post->post_title . '"');
echo '</ul></div>';

echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms taxonomy="post_tag" before="Tagged "]', hybrid_get_textdomain() ) . '</div>' );
endwhile;
?>
<div class="loop-nav">

<?php previous_post_link( '<div class="previous">' . __( '%link', hybrid_get_textdomain() ) . '</div>', '%title', TRUE ); ?>
<?php next_post_link( '<div class="next">' . __( '%link', hybrid_get_textdomain() ) . '</div>', '%title', TRUE ); ?>
</div><!-- .loop-nav -->
<div class="clr"></div>
<?php foxyshop_include('footer'); ?>
</div>
<?php } ?>

<?php
get_footer(); ?>

Answers (2)

2011-06-27

Maor Barazany answers:

You may want to check the [[LINK href="http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/"]]nextprevious-post-link-plus plugin[[/LINK]] that can help you achieve full support for cpt's and single navigation


Maor Barazany comments:

[[LINK href="http://www.ambrosite.com/plugins/next-previous-post-link-plus-for-wordpress"]]Here[[/LINK]] you can see instruction of all the parameters you can use with the 2 new functions of the plugin


Rick Bible comments:

let me play with this and see if it works. If so, you've solved my problem

2011-06-27

Utkarsh Kukreti answers:

What custom post type / taxonomy do you want this to work with?


add_filter('get_previous_post_where', 'cpt_adjacent_post_where');
add_filter('get_next_post_where', 'cpt_adjacent_post_where');

function cpt_adjacent_post_where($join) {
$post_type = 'foxyshop_product';
$taxonomy = 'foxyshop_categories';
global $post;
if($post->post_type == $post_type) {
return str_replace("'category'", "'{$taxonomy}'", $join);
} else {
return $join;
}
}


Rick Bible comments:

there are "products" and "product categories"... if I have 5 product categories. I'm assuming post type / taxonomy must be for each product category, so
three yards or less
thirty yards or less
embroidereds

I will have many more, but this would be enough for me to understand, and trouble shoot.


Rick Bible comments:

By the way, post type is foxyshop_product


Utkarsh Kukreti comments:

Please try the code I added to the post above. This will filter the posts with post_type foxyshop_product to use foxyshop_categories taxonomy, in previous/next post links.


Rick Bible comments:

this does not work. it would be my preference to not use a plugin... but I added this to my functions, no change


Utkarsh Kukreti comments:

Which version of WP are you using? Did you send the third param as TRUE?


Rick Bible comments:

newest wp version and I tried true and false, with the same results