首页 文章

自定义Wordpress生成的痕迹链接

提问于
浏览
0

美好的一天

我正在使用Wordpress,我使用的是breadcrumbs插件(Breadcrumb NavXT) . 现在它工作得很好,我希望自定义它链接到 specific 链接的方式:

Now here is the scenario:

我有一个页面,在页面上是帖子的链接 . 因此,当您单击页面上的某个链接时,它会将您带到帖子中 . 现在这个帖子属于名为Drill Rigs的类别,而Drill Rigs属于产品的子类别 .

现在在帖子页面上,其中包含“产品>钻井平台”(父/子)类别,面包屑显示以下方式:

Home>products>drill rigs>postname

问题是,你点击上面的产品链接,它会带你到产品的类别页面:

siteurl/category/products

而不是被称为产品的实际wordpress页面(包含链接到上述帖子的链接:

siteurl /页面的绝对链接,这是一个独特的链接,例如 . SITEURL / 803-2

据我所知,你不能改变从一个类别(对帖子来说是唯一的)到一个页面的路径,无论是在wordpress还是插件中 .

我能想到的最好的方法是将自定义jquery或php添加到帖子php页面(或索引/ Headers 页面),查找包含托管 Headers 'products'的锚标记的容器div ...然后替换它使用我的自定义唯一页面网址锚标记...

我该怎么做......?

4 回答

  • 0

    在这里尝试使用function.php中的nav Navxt插件

    http://daniel.shortens.net/woocommerce-breadcrumb-navxt

  • 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>';
    }
    

    }

    试试这个希望,这可能对你有帮助

  • 1

    您可以使用该函数通过编码设置Breadcrumb:

    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(); ?>
    

    希望对你有帮助 ...

  • 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
    

    是我想要链接到的年龄的网址...

相关问题