Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce中带有“阅读更多”标签的产品存档说明_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce中带有“阅读更多”标签的产品存档说明

Php WooCommerce中带有“阅读更多”标签的产品存档说明,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,是否可以将read more标记添加到WooCommerce归档描述中?我找到了一些解决方案,但它们都是针对单个产品页面的,例如下面的例子。找不到在存档页上完成此操作的方法。我想在移动设备上获得read more标签,否则内容会太长,产品一开始就看不见 这就是我目前拥有的代码,放在category.php中 <div class="nm-shop-title"> <div class="nm-row"> <div

是否可以将read more标记添加到WooCommerce归档描述中?我找到了一些解决方案,但它们都是针对单个产品页面的,例如下面的例子。找不到在存档页上完成此操作的方法。我想在移动设备上获得read more标签,否则内容会太长,产品一开始就看不见

这就是我目前拥有的代码,放在category.php中

      <div class="nm-shop-title">
        <div class="nm-row"> 
            <div class="col-xs-12">
                 <h1 class="cat-title"><?php woocommerce_page_title(); ?></h1>
                   <?php 
                        /**
                         * woocommerce_archive_description hook
                         *
                         * @hooked woocommerce_taxonomy_archive_description - 10
                         * @hooked woocommerce_product_archive_description - 10
                         */
                        do_action( 'woocommerce_archive_description' );
                    ?>
            </div>
        </div>
    </div>

如果您的代码在products循环中,请尝试删除
do_操作(“woocommerce_archive_description”)
并将其添加到标题下方

<a href="<?php echo get_the_permalink(); ?>"><?php _e('read more', 'woocommerce');?></a>


这将显示一个“阅读更多”链接,该链接将重定向到您的产品。

我找到了一个解决方案,它对我非常有用

我用一点JQuery修复了它。出现“阅读更多”链接的文本由data js=“content”属性触发。比如说

<p data-js="content"> This is the Text where it should appear></p>

这是它应该出现的文本>

使用下面的JQuery,我触发了触发器。因此,它仅在移动设备上显示,并且仅在段落具有data js=“content”属性的位置显示

if(window.outerWidth < 991) {
// Select all text areas
var textArea = document.querySelectorAll('[data-js=content]'),    
    maxText = 100;

// For each one...
[].forEach.call( textArea, function( el ) {

  var textAreaLength = el.innerHTML.length,
    teaserText = el.innerHTML.substr(0, 100),
    fullText = el.innerHTML,
    showTeaser = false;    

  // Check to see if this text length is more
  // than the max
  if (textAreaLength >= maxText) {
    // Set flag
    showTeaser = true;

    // Set teaser text  
    el.innerHTML = teaserText;
    el.innerHTML += '...';

    // Create button
    var button = document.createElement('button');
    button.innerHTML = 'Mehr anzeigen';
    button.classList.add('button');
    el.appendChild(button);

    // Button click event
    button.onclick = function () {
      if (showTeaser === true) {
        // Update flag
        showTeaser = false;

        // Update button text
        this.innerHTML = 'Weniger anzeigen';

        // Show full text
        el.innerHTML = fullText;

        // Re-append the button
        el.appendChild(this);
      } else {
        // Update flag
        showTeaser = true;

        // Update button text
        this.innerHTML = 'Mehr anzeigen';

        // Show teaser text
        el.innerHTML = teaserText;
        el.innerHTML += '...';

        // Re-append the button
        el.appendChild(this);
      }
      return false;
    };
  } else { 
    // Show full text
    el.innerHTML = fullText;
  }   

});
}
if(window.outerWidth<991){
//选择所有文本区域
var textArea=document.querySelectorAll(“[data js=content]”),
maxText=100;
//对于每一个。。。
[]forEach.call(文本区域,函数(el){
var textAreaLength=el.innerHTML.length,
steasertext=el.innerHTML.substr(01100),
全文=el.innerHTML,
showtaster=false;
//检查此文本长度是否更大
//超过最大值
如果(textAreaLength>=maxText){
//设旗
showtaster=true;
//设置摘要文本
el.innerHTML=striesterText;
el.innerHTML+='…';
//创建按钮
var button=document.createElement('button');
button.innerHTML='Mehr-anzegin';
button.classList.add('button');
el.追加子项(按钮);
//按钮点击事件
button.onclick=函数(){
if(showtaster===true){
//更新标志
showtaster=false;
//更新按钮文本
this.innerHTML='Weniger Anzegin';
//显示全文
el.innerHTML=全文;
//重新添加按钮
el.儿童(本);
}否则{
//更新标志
showtaster=true;
//更新按钮文本
this.innerHTML='Mehr-anzegin';
//显示摘要文本
el.innerHTML=striesterText;
el.innerHTML+='…';
//重新添加按钮
el.儿童(本);
}
返回false;
};
}否则{
//显示全文
el.innerHTML=全文;
}   
});
}

请分享您的代码。我想帮你。你指的是存档页上的产品描述,对吗?是的,没错。我用现在显示描述的代码更新了我的问题