0

Good Day

I am using Wordpress, and I am using a breadcrumbs plugin (Breadcrumb NavXT). Now it works great, exept that I would like to customize the way it links to a specific link:

Now here is the scenario:

I have a page, and on the page are links to posts. So when you click on one of the links on the page, it takes you to the post. Now this posts belongs to a category named Drill Rigs, and Drill Rigs is a child category of Products.

Now on the post page, which has category 'products>drill rigs' (parent/child), the breadcrumb shows the following way:

Home>products>drill rigs>postname

Problem is, that of you click on the products link above, it takes you to the category page of products:

siteurl/category/products

and not the actual wordpress page that is called products (that contains the links linking to the posts mentioned above:

siteurl/absolute link to the page, which is a unique link eg. siteurl/803-2

Now as far as I know, you cannot change the path from a category (which are unique to posts) to a page, neither in wordpress nor the plugin.

The best way I can think of is to add custom jquery or php to the posts php page (or index/header pages) that looks for the container div containing the anchor tags that hosts the title 'products'...and then replacing that anchor tag with my custom unique page url...

How would I do this...?

4

4 回答 4

1
function the_breadcrumb() {

$sep = '/';

if (!is_front_page()) {

    echo '<div class="breadcrumbs">';
    echo '<a href="';
    echo get_option('home');
    echo '">';
    bloginfo('name');
    echo '</a>' . $sep;

    if (is_category() || is_single() ){
        the_category('title_li=');
    } elseif (is_archive() || is_single()){
        if ( is_day() ) {
            printf( __( '%s', 'text_domain' ), get_the_date() );
        } elseif ( is_month() ) {
            printf( __( '%s', 'text_domain' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
        } elseif ( is_year() ) {
            printf( __( '%s', 'text_domain' ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
        } else {
            _e( 'Blog Archives', 'text_domain' );
        }
    }

    if (is_single()) {
        echo $sep;
        the_title();
    }

    if (is_page()) {
        echo the_title();
    }

    if (is_home()){
        global $post;
        $page_for_posts_id = get_option('page_for_posts');
        if ( $page_for_posts_id ) { 
            $post = get_page($page_for_posts_id);
            setup_postdata($post);
            the_title();
            rewind_posts();
        }
    }

    echo '</div>';
}

}

试试这个希望这可以帮助你

于 2013-03-15T12:39:05.173 回答
1

此代码适用于您的帖子的异步内容:(复制到 functions.php 中)

function ariane() {
    $cat_id         = get_the_category()[0]->term_id;
    $breadcrumb     = '<li>' . get_the_title() . '</li>';

    $if_parent = TRUE;

    while($if_parent == TRUE) :
        $cat_object     = get_category($cat_id);
        $cat            = $cat_object->term_id;
        $categoryURL    = get_category_link($cat);
        $name           = $cat_object->name;
        $cat_id         = $cat_object->parent;              

        $add_link       = '<li><a href="' . $categoryURL . '">' . $name . '</a></li>';

        $breadcrumb     = substr_replace($breadcrumb, $add_link, 0, 0);

        if($cat_id  == 0) :
            $if_parent = FALSE;
        endif;
    endwhile;

    echo '<ul>' . $breadcrumb . '</ul>';    
}

在您的archive.php 或循环中的WP_QUERY

<div class="ariane"><?php ariane(); ?></div>

在 CSS 中:

.ariane ul{
    display: flex;
    justify-content: flex-start;
    align-items: center;
}  
.ariane li:not(:last-child):after {
    content: '>';
    margin: 0 5px;
}
于 2019-06-07T12:02:35.487 回答
0

您可以使用该功能通过编码设置您的面包屑:

function the_breadcrumb() {
if (!is_home()) {
    echo '<a href="';
    echo get_option('home');
    echo '">';
    echo "Home";//bloginfo('name');
    echo "</a> / ";
    if (is_category() || is_single()) {
        the_category('title_li=');
        if (is_single()) {
            echo " / ";
            the_title();
        }
    } elseif (is_page()) {
        echo the_title();
    }
}

}

把上面的代码放到function.php文件中

您只需调用要显示 bredcrumb 的函数

<?php the_breadcrumb(); ?>

希望对你有帮助 ...

于 2013-03-15T08:50:53.127 回答
0
<script type="text/javascript">
$('#breadcrumbs .category[href="http://mysite.com/category/products"]').attr('href','http://mysite.com/803-2');
</script>

在哪里:

http://mysite.com/803-2

是我要链接到的页面的 url [年龄...

于 2013-03-15T12:55:05.400 回答