好日子
我使用Wordpress,我使用的是面包屑插件( NavXT)。现在,我想定制它链接到特定的链接的方式,这是很好的,非常有效的:
现在是这样的场景:
我有一个网页,并在页面上是链接到帖子。所以当你点击页面上的一个链接时,它会把你带到帖子。现在,这篇文章属于一个名为“钻机”的类别,而钻机是一个子产品类别。
现在,在具有类别'products>drill钻机‘(父/子)的post页面上,面包屑显示了以下方式:
Home>products>drill rigs>postname问题是,如果您单击上面的“产品”链接,它会将您带到产品类别页面:
siteurl/category/products而不是名为“产品”的实际wordpress页面(包含链接到上述帖子的链接):
站点/绝对链接到页面,这是一个独特的链接,例如。网站网址1/803-2
现在,据我所知,您不能将路径从一个类别(这是唯一的文章)到一个页面,无论是在wordpress或插件。
我能想到的最好的方法是将自定义的jquery或php添加到posts php页面(或索引/页眉页),以查找包含承载标题“products”的锚标记的容器div .然后用我的自定义唯一页面url替换该锚标记.
我怎么做.?
发布于 2013-03-15 12:39:05
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>';
}}
试试这个,希望这能帮到你。
发布于 2019-06-07 12:02:35
这段代码适用于文章的异步内容:(在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;
}发布于 2013-03-15 08:50:53
您可以通过编写代码来使用该函数来设置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(); ?>希望这能帮你..。
https://stackoverflow.com/questions/15427620
复制相似问题