【问题标题】:Replace Breadcrumb with static message用静态消息替换面包屑
【发布时间】:2019-04-11 18:49:09
【问题描述】:

我有一个简单的主题网站。我需要用一条独特的消息替换面包屑。有显示类别的商店页面,子类别页面,然后是该子类别页面的产品。我需要为这 3 个页面而不是面包屑显示 3 个不同的消息。

我对代码知之甚少,所以请帮助我完成代码,将其复制并粘贴到子主题内的功能性 php 文件中。

目前,通过编辑 Breadcrumb.php 文件 (/public_html/wp-content/themes/flatsome/woocommerce/global/breadcrumb.php),我设法用一条消息(相同消息)替换了 3 页的面包屑 -

<?php
/**
 * Shop breadcrumb
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.0
 * @see         woocommerce_breadcrumb()
 */

if (!defined( 'ABSPATH' )){
  exit;
}


echo " my message";


我需要的是 php 代码将先前代码中的 [echo " my message";] 更改为特定页面的特定消息,并包含在先前代码中。一些代码如:

if page is (shop page or page ID=****) then echo " message one";

 else if (page is category page or page id =****) then  echo " message two",

 else  echo " message three"

所以最终的代码会是这样的:


<?php
/**
 * Shop breadcrumb
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.0
 * @see         woocommerce_breadcrumb()
 */

if (!defined( 'ABSPATH' )){
  exit;
}


if page is (shop page or page ID=****) then echo " message one";

 else if (page is category page or page id =****) then  echo " message two",

 else  echo " message three"


提前谢谢你

【问题讨论】:

    标签: php breadcrumbs


    【解决方案1】:

    你可以使用WordPress函数is_page()来实现你想做的事情。

    if (is_page(123)) {
        echo "message one";
    } else if (is_page(456)) {
        echo "message two";
    } else {
        echo "message three";
    }
    

    在本例中,123456 是页面 ID。 is_page() 采用以下参数:

    $页面 (int|string|array) (可选)页面 ID、标题、slug 或此类的数组。

    (Source)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 2018-01-28
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多