首页 \ 问答 \ WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)

WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)

我有一个产品循环在我的主页上显示8个产品。 它只是一个从产品列表的末尾开始到开头的循环,并显示我的所有产品,直到它到达第8个。 当我提出一个条件语句,我只想要显示某些标题的产品时,它只会选择那些,但只能从没有条件语句的情况下显示的产品列表中选择。

例如,考虑商店中所有产品的列表:

[列表的开头]'Globus 1''Globus 2'[......更多产品...]'Kompozycja 6''Kompozycja 7'[列表末尾]

我的循环抓取最后一项到第一项的项目,并将显示的产品数量限制为8.我已经放置了一个条件语句,我只想显示“Kompozycja 7”并且它有效。 但是,如果我指定的名称不是列表中最后8个项目之一,那么它将无效。 例如,我将选择'Globus 1'。 它不会显示,因为它不属于列表中的最后8个项目。

这是我的循环:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 8
    );
$loop = new WP_Query( $args );

if ( $loop->have_posts() ) {
        while ( $loop->have_posts() ) : $loop->the_post();
        if (get_the_title($post->ID) == 'Kompozycja 7' || get_the_title($post->ID) == 'Kompozycja 2') {
                woocommerce_get_template_part( 'content', 'product' );
        }   
        endwhile;
    } else {
        echo __( 'No products found' );
    }

有人可以帮我吗?


I have got a product loop to display 8 products on my homepage. It is simply a loop which starts from the end of the product list to the beginning and displays all of my products until it reaches the 8th one. When I put a conditional statement that I want only products with certain titles displayed it does select only those, but only from the list of products which would be displayed without the conditional statement.

For example consider such a list of ALL products in the shop:

[beginning of the list] 'Globus 1' 'Globus 2' [... some more products ...] 'Kompozycja 6' 'Kompozycja 7' [end of the list]

My loop grabs items from the last item to the first one and limits the amount of products displayed to 8. I've put a conditional statement that I want only 'Kompozycja 7' to be displayed and it worked. But if I specify a name which is not one of the last 8 items on the list then it will not work. For example I will choose 'Globus 1'. It won't be displayed because it does not belong to the last 8 items on the list.

Here is my loop:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 8
    );
$loop = new WP_Query( $args );

if ( $loop->have_posts() ) {
        while ( $loop->have_posts() ) : $loop->the_post();
        if (get_the_title($post->ID) == 'Kompozycja 7' || get_the_title($post->ID) == 'Kompozycja 2') {
                woocommerce_get_template_part( 'content', 'product' );
        }   
        endwhile;
    } else {
        echo __( 'No products found' );
    }

Could anybody help me with that?


原文:https://stackoverflow.com/questions/22813097
更新时间:2024-05-05 17:05

最满意答案

以下测试您的代码将解决问题:

inStream.Position = 0;

将它设置为class CUnZip - UnZip Method中的argh.Flush()

细节:

当您在CUnZip类中重用MemoryStream时,其位置设置为写入的最后一个字节并执行任何操作,需要将其读取,您需要将position重置为开头(0),否则它什么都没有因此,即使当stream包含数据时,它也无法读取,因为它指向stream的末尾


Tested your code following will resolve the issue:

inStream.Position = 0;

Set it post argh.Flush() in the class CUnZip - UnZip Method

Details:

As you are reusing the MemoryStream in the CUnZip class, its position is set to the last byte written and to do any operation, that needs it to be read, you need to reset the position to the beginning (0), else it has nothing to read, therefore even when stream contained the data it cannot be read, as it was pointing to the end of stream

相关问答

更多
  • 放气只是压缩算法。 GZip实际上是一种格式。 如果您使用GZipStream压缩文件(并使用扩展名.gz保存),结果实际上可以由诸如WinZip或gzip工具之类的存档打开。 如果您使用DeflateStream压缩,则这些工具将无法识别该文件。 如果压缩文件被设计为由这些工具打开,那么使用GZipStream而不是DeflateStream是至关重要的。 如果您通过不可靠的介质(即互联网连接)传输大量数据,而不使用诸如TCP / IP之类的纠错协议,那么我也认为这一点至关重要。 例如,您可能通过串行端口 ...
  • 我已经把最后45分钟包围了这个问题,但我无法解释为什么它不起作用。 不知怎的,DeflateStream类没有正确解码你的数据。 我编写了自己的GZip解析器(我可以共享代码,如果有人想检查它),它读取所有标题并检查它们的有效性(以确保那里没有有趣的东西),然后使用DeflateStream来膨胀实际数据,但与您的文件,它仍然只是让我第一行。 如果我使用你的日志文件使用GZipStream重新压缩(在用winrar首先解压缩之后),那么我的自己的解析器和你自己的样本再次解压缩。 网上似乎有一些关于微软实施D ...
  • 解压缩方法中存在一个错误。 该代码不读取bSource内容。 相反,它覆盖了从基于空内存流创建的空gzip读取的内容。 基本上你的代码版本正在做什么: //create empty memory using (MemoryStream ms = new MemoryStream()) //create gzip stream over empty memory stream using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compre ...
  • 你是以错误的方式管道。 固定: using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) using (MemoryStream ms = new MemoryStream(resource)) using (GZipStream zs = new GZipStream(ms, CompressionMode.Decompress)) { zs.CopyTo(fs); } You are p ...
  • 你不能用GZipStream做到这GZipStream 。 你需要一个第三方库。 可能是SharpZipLib中最好的一个。 我过去在项目中使用过这个,而且它很容易使用。 而且它已经存在了一段时间,所以应该非常稳定且没有错误。 You can't do this with a GZipStream. You'll need a 3rd party library. Probably the best one out there is SharpZipLib. I've used this on projec ...
  • 以下测试您的代码将解决问题: inStream.Position = 0; 将它设置为class CUnZip - UnZip Method中的argh.Flush() 细节: 当您在CUnZip类中重用MemoryStream时,其位置设置为写入的最后一个字节并执行任何操作,需要将其读取,您需要将position重置为开头(0),否则它什么都没有因此,即使当stream包含数据时,它也无法读取,因为它指向stream的末尾 Tested your code following will resolve ...
  • 您的输出文件只包含一行(gzip) - 但它包含除换行符以外的所有文本数据。 您反复调用ReadLine() ,它返回一行文本, 没有换行符并将该文本转换为字节。 所以如果你有一个输入文件,它有: abc def ghi 你最终得到的输出文件是压缩版本 abcdefghi 如果您不想要这种行为,为什么甚至首先要通过StreamReader呢? 只需从输入FileStream直接复制到GZipStream一块,或者如果你使用的是.NET 4,则使用Stream.CopyTo : // Note how m ...
  • GZipStream不实现从一个流解压缩多个文件的方法。 尝试使用处理ZIP存档(如DotNetZip)的库。 如果您绝对想要使用GZipStream,则可以在输入流中搜索gzip标头 ,然后仅向属于每个文件的流的部分提供GZipStream。 GZipStream does not implement methods to decompress multiple files from one stream. Try using a library which handles ZIP archives su ...
  • 对于Base64,你有来自Apache Commons的Base64 类 ,以及带有String并返回byte[]的decodeBase64方法。 然后,您可以将生成的byte[]读入ByteArrayInputStream 。 最后,将ByteArrayInputStream传递给GZipInputStream并读取未压缩的字节。 代码看起来像这样的东西: public static String Decompress(String zipText) throws IOException { by ...
  • 如果要将数据插入到流中,请确保在解压缩之前寻找其原点。 以下应该解决你的麻烦: using (var fileStream = new MemoryStream()) { client.DownloadFile(file.FullName, fileStream); // Success! All is good here, so far. :) fileStream.Seek(0, SeekOr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。