<?php
    // Inicializar variables
    $home_url = home_url('/');
    $home_text = 'Inicio';
    $breadcrumbs_html = '';

    // Obtener información de la página actual
    $current_page = get_queried_object();
    
    if ($current_page) {
        $current_page_title = $current_page->post_title;
        $current_page_url = get_permalink($current_page->ID);
    }

    // Añadir enlace a la página de inicio
    $breadcrumbs_html .= '<a href="' . $home_url . '">' . $home_text . '</a> | ';

    // Añadir enlaces para páginas anteriores
    if (is_single()) {
        // Si es una publicación, añadir enlace a la categoría de la publicación
        $category = get_the_category($current_page->ID);
        if ($category && isset($category[0])) {
            $category_url = get_category_link($category[0]->cat_ID);
            $breadcrumbs_html .= '<a href="' . $category_url . '">' . $category[0]->cat_name . '</a> | ';
        }
    } elseif (is_page()) {
        // Si es una página, añadir enlaces para todas las páginas anteriores
        $parent_id  = $current_page->post_parent;
        while ($parent_id) {
            $page = get_page($parent_id);
            if ($page) {
                $breadcrumbs_html = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a> > ' . $breadcrumbs_html;
                $parent_id  = $page->post_parent;
            } else {
                break; // Salir del bucle si no se puede obtener la página principal
            }
        }
    }

    // Añadir enlace a la página actual
    if (isset($current_page_title) && isset($current_page_url)) {
        $breadcrumbs_html .= '<a href="' . $current_page_url . '">' . $current_page_title . '</a>';
    }

    // Devolver migas de pan como cadena de texto HTML
    echo '<div class="breadcrumbs">' . $breadcrumbs_html . '</div>';
?>

01 – Blog single (Class-based)

Related posts

<script>
  /*Source: https://github.com/Krzysztof-Antosik/Two-direction-Sticky-Sidebar*/
  
  // Verificar el ancho de pantalla al cargar y redimensionar
  function checkScreenWidth() {
    if (window.innerWidth <= 767) {
      // Si la pantalla es menor o igual a 676px, no ejecutar el código
      return;
    }

    const stickyElement = document.querySelector('.fb-sidebar__aside');
    const startPosition = stickyElement.getBoundingClientRect().top;

    let endScroll = window.innerHeight - stickyElement.offsetHeight - 500;
    let currPos = window.scrollY;
    let screenHeight = window.innerHeight;
    let stickyElementHeight = stickyElement.offsetHeight;
    let topGap = 40;
    let bottomGap = 40;

    setTimeout(() => {
      if (stickyElement.hasAttribute('data-top-gap')) {
        const dataTopGap = stickyElement.getAttribute('data-top-gap');
        topGap = dataTopGap === 'auto' ? startPosition : parseInt(dataTopGap);
      }

      if (stickyElement.hasAttribute('data-bottom-gap')) {
        bottomGap = parseInt(stickyElement.getAttribute('data-bottom-gap'));
      }
    }, 100);

    stickyElement.style.position = 'sticky';
    stickyElement.style.top = `${topGap}px`;
    stickyElement.style.height = 'fit-content';

    function positionStickySidebar() {
      endScroll = window.innerHeight - stickyElement.offsetHeight - bottomGap;
      const stickyElementTop = parseInt(stickyElement.style.top.replace('px', ''));

      if (stickyElementHeight + topGap + bottomGap > screenHeight) {
        if (window.scrollY < currPos) {
          if (stickyElementTop < topGap) {
            stickyElement.style.top = `${stickyElementTop + currPos - window.scrollY}px`;
          } else if (stickyElementTop >= topGap && stickyElementTop !== topGap) {
            stickyElement.style.top = `${topGap}px`;
          }
        } else {
          if (stickyElementTop > endScroll) {
            stickyElement.style.top = `${stickyElementTop + currPos - window.scrollY}px`;
          } else if (stickyElementTop < endScroll && stickyElementTop !== endScroll) {
            stickyElement.style.top = `${endScroll}px`;
          }
        }
      } else {
        stickyElement.style.top = `${topGap}px`;
      }
      currPos = window.scrollY;
    }

    function stickyElementToMe() {
      stickyElement.style.top = `${topGap}px`;
    }

    function updateSticky() {
      screenHeight = window.innerHeight;
      stickyElementHeight = stickyElement.offsetHeight;
      positionStickySidebar();
    }

    setTimeout(() => {
      window.addEventListener('resize', () => {
        currPos = window.scrollY;
        updateSticky();
      });

      document.addEventListener('scroll', updateSticky, {
        capture: true,
        passive: true
      });
    }, 1000);
  }

  // Verificar el ancho de pantalla al cargar y redimensionar
  window.addEventListener('load', checkScreenWidth);
  window.addEventListener('resize', checkScreenWidth);
</script>