0

I have tried everything, and looked everywhere for a solution for this problem..

I have a custom type "boat", which has some custom fields. I can display a list of boats on a page, and when a row is clicked the details are displayed in single-boat.php.

One of the custom fields is a select box (motor, sail). So in my main menu I can select a menu option which will display motor or sail filtered on this field.

However, from the single-boat.php file I cannot return from the breadcrumb, to the relevant page listing my boats (motor or sail).

Can any one help, before I start banging my head against the wall in desperation?

Many thanks,

1 Answer 1

1

Ok, so I didn't get a reply, but I worked this out as as solution and I hope it will be useful to others.

I am using the evolve template, so when you see evolve it is referring to something in the evolve template; e.g. evolve_breadcrumb() is a function used by the evolve template.

This is the scenario:

  • Custom post type: boat
  • Types of boat: motor, sail
  • Languages: english, spanish

This has to select the correct menu for post or boat / motor or sail / english or spanish.

First step: select evolve_breadcrumb() for a standard post OR use new function for a custom single page single_boat_evolve_breadcrumb().

Some of the fields in the code refer to custom fields... e.g. $typeofboat refers to Motor or Sail boat.

/**
 * Start breadcrumbs
 */ 

// selects standard breadcrumb function or specific for single boat page
// standard returns to blog / boat returns to single page parent
function choose_and_display_breadcrumbs() {
  if(is_single() && is_singular("boat")) {
    single_boat_evolve_breadcrumb();
  } else {
    evolve_breadcrumb();
  }
}


// get a page ID by  page slug 
function get_ID_by_page_slug($page_slug) {
    $page = get_page_by_path($page_slug);
    if ($page) {
        return $page->ID;
    } else {
        return null;
    }
}
/**
 *  for single page which is a boat
 */
function single_boat_evolve_breadcrumb() {
        global $data,$post;

        echo '<ul class="breadcrumbs">';

        echo '<li><a class="home" href="';
        echo home_url();
        echo '">'.__('Home', 'evolve');
        echo "</a></li>";

        $params['link_none'] = '';
        $separator = '';

        if(is_single() && is_singular("boat")) {

            $parentID = 0;
            $parentpagelink = ""; 
            $availability = strtolower( get_custom_field('availability'));
            $typeofboat = strtolower( get_custom_field('type_of_boat'));
            $currentlanguage = pll_current_language();

            if ( $currentlanguage == 'en') {
                if ($availability == 'sold') {
                  $parentID = get_ID_by_page_slug('boats-sold');
                  $parentpagelink = get_page_link( $parentID);

                } else {
                    switch ($typeofboat) {
                      case 'yacht':
                          $parentID = get_ID_by_page_slug('sail-brokerage');
                          $parentpagelink = get_page_link( $parentID);
                          break;

                      case 'motorboat':
                          $parentID = get_ID_by_page_slug('motor-brokerage');
                          $parentpagelink = get_page_link( $parentID); 
                          break;
                      default:

                        break;
                    }

                }

            } elseif ($currentlanguage == 'es') {
                if ($availability == 'sold') {
                  $parentID = get_ID_by_page_slug('barcos-vendidos');
                  $parentpagelink = get_page_link( $parentID);

                } else {

                  switch ($typeofboat) {
                    case 'yacht':
                        $parentID = get_ID_by_page_slug('corretaje-de-vela-2');
                        $parentpagelink = get_page_link( $parentID);
                        break;

                    case 'motorboat':
                        $parentID = get_ID_by_page_slug('corretaje-de-motor');
                        $parentpagelink = get_page_link( $parentID); 
                        break;

                    default:  
                      break;
                  } 
                } 
            }

        }  
        echo '<li>';
        echo '<a href="' . $parentpagelink . '" title="' . $typeofboat . '">' . get_the_title($parentID) . '</a>';
        echo '</li>';
        echo '<li>'. get_the_title() .'</li>';
      echo "</ul>";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.