为什么我不能只是改变一个href硬编码的url链接


Why I cannot just change the a href to a hardcoded url link?

我希望页面http://zanifesto.com/product/boise-infographic/回到http://zanifesto.com/gallery,而不是顶部的" back to"链接的Infographics类别页面。

当我用上面提到的画廊url替换下面的。home_url等时,它会出错。

我正在寻找理解为什么php代码不像我替换一个url为另一个。

<div class="product_navigation desktops">
            <?php
                $term_list = '';
                $j=0;
                foreach ($terms as $term) {
                    if($term->parent==0){
                        $j++;
                        if( $j <= 1 ){
                            $term_list .= '<a href="'.home_url() . '/' . $category_slug . '/'. $term->slug . '">' . $term->name . '</a>';
                        }
                    }
                }
                if(strlen($term_list) > 0){ echo '<div class="nav-back">&lsaquo;&nbsp;&nbsp;&nbsp;'. __('Back to ', 'theretailer').$term_list.'</div>'; };
            ?>
            <?php if (function_exists('be_previous_post_link')) { ?>
            <div class="nav-next-single"><?php be_next_post_link( '%link', '', true,'', 'product_cat' ); ?></div>
            <div class="nav-previous-single"><?php be_previous_post_link( '%link', '', true,'', 'product_cat' ); ?></div>
            <div class="nav-prev-next-txt"><?php _e('Prev / Next', 'theretailer'); ?></div>
            <?php } ?>
            <div class="clr"></div>
        </div>
        <?php } ?>

这段代码可以做你想做的…

<?php
    $term_list = '';
    $j=0;
    foreach ($terms as $term) {
        if($term->parent==0){
            $j++;
            if( $j <= 1 ){
                $url=home_url() . '/' . $category_slug . '/'. $term->slug;
                if($url=='http://zanifesto.com/product-category/infographics'){
                    $url='http://zanifesto.com/gallery';
                }
                $term_list .= '<a href="'. $url . '">' . $term->name . '</a>';
            }
        }
    }
    if(strlen($term_list) > 0){ echo '<div class="nav-back">&lsaquo;&nbsp;&nbsp;&nbsp;'. __('Back to ', 'theretailer').$term_list.'</div>'; };
?>