【问题标题】:Error 404 on the side because of <?php echo wc_get_cart_url; ?>由于 <?php echo wc_get_cart_url; 而出现错误 404 ?>
【发布时间】:2020-01-11 06:02:22
【问题描述】:

由于购物车元素,我收到错误 404。

这里是脚本(可以在主题文件夹下的header.php中找到):

<ul class="mobile-topnav container"><li>
<div class="mini-cart">
<a href="<?php echo wc_get_cart_url; ?>" class="cart-contents" title="<?php _e('View Cart', 'trav') ?>">
<i class="soap-icon-shopping"></i>
<div class="item-count">cart->get_cart_contents_count(); ?></div>
</a>
</div>

搜索引擎收到错误 404 .. 数百页。

示例报告死链接:

https://example.com/..?php%20echo%20wc_get_cart_url;%20?> https://example.com/privacy-policy/..?php%20echo%20wc_get_cart_url;%20?> .....(有超过200页这样的)

(我不知道为什么要在链接末尾添加代码)但由于 googlebot 扫描问题,我需要快速修复它。

【问题讨论】:

    标签: wordpress http-status-code-404


    【解决方案1】:

    您在此行的代码中有错误:

    <div class="item-count">cart->get_cart_contents_count(); ?></div>
    

    应该是:

    <div class="item-count"><?php echo cart->get_cart_contents_count(); ?></div>
    

    【讨论】:

    • 感谢您的快速回复!我做了改变,但我仍然得到同样的错误。 (我使用 brokenlinkcheck 扫描我的网站)
    • 您好,您发送的新代码示例有同样的错误。您正在尝试运行函数 get_cart_contents_count() 但它需要在 PHP 标记内。例如。 我还认为您需要回显 get_cart_contents_count() 的返回值,因此在其前面添加“echo”,例如get_cart_contents_count(); ?>
    【解决方案2】:
    <a href="<?php echo wc_get_cart_url(); ?>" class="cart-contents" title="<?php _e('View Cart', 'trav'); ?>">
    <i class="soap-icon-shopping"></i>
    <div class="item-count">/<?php cart->get_cart_contents_count(); ?></div>
    </a>
    

    您的代码缺少用于函数调用的开放标记、分号和括号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 2015-06-05
      相关资源
      最近更新 更多