我正在使用Wordpress link to site构建一个网站,这是一个具有自定义帖子类型(产品)和自定义帖子分类(product_category)的站点。
在Category页面上,我必须按子类别过滤产品。我找到了带有教程的filterable.js。
我的问题是:如果我点击任何子类别(Filter-Item),浏览器(Chrome和Filezilla)就不能再工作了。
如果我点击过滤器,浏览器在长时间加载后显示“正在处理请求”,浏览器会给我一个错误。以下是浏览器错误的屏幕截图:http://farbstrakt.com/screenshot.png
我认为问题出在我如何更改URL。我日复一日地寻找任何解决方案,但一无所获。我找不到错误
下面是我的分类法-product_category.php y.php
<div class="container middler" id="demo">
<ul class="filter-wrapper clearfix" id="portfolio-filter">
<?php
$args = array(
'show_count' => false,
'child_of' => get_queried_object()->term_id,
'taxonomy' => 'product_category',
'title_li' =>'',
);
$terms = get_categories($args);
$count = count($terms);
if ( $count > 0 ){
echo '<li class="cl-effect-2"><div><a href="#all" title=""><span data-hover="Alle">Alle</span></a></div></li>';
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(' ', '-', $termname);
$termname = strtolower($term->name);
$termname = str_replace(' ', '-', $termname);
echo '<li class="cl-effect-2">
<div>
<a href="#'.$termname.'">
<span data-hover="'.$term->name.'">'.$term->name.'</span>
</a>
</div>
</li>';
}
}
?>
</ul>
<?php
$loop = new WP_Query(array('post_type' => 'product', 'posts_per_page' => -1));
$count =0;
?>
<div id="portfolio-wrapper">
<ul class="grid effect-2 item-wrapper clearfix filter-all" id="grid">
<?php if ( $loop ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$terms = get_the_terms( $post->ID, 'product_category' );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term )
{
$links[] = $term->name;
}
$links = str_replace(' ', '-', $links);
$tax = join( " ", $links );
else :
$tax = '';
endif;
?>
<?php $infos = get_post_custom_values('_url'); ?>
<li class="<?php echo strtolower($tax); ?> all ">
<div>
<figure>
<a href="<?php the_permalink() ?>" class="img-link"><?php the_post_thumbnail( array(400, 160) ); ?></a>
<figcaption><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></figcpation>
</figure>
</div>
</li>
<?php endwhile; else: ?>
<p class="no-products">NO products
</p>
</ul>
<?php endif; ?>这是上面代码中的一小段代码,我认为其中一定有错误。
<?php
$terms = get_the_terms( $post->ID, 'product_category' );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term )
{
$links[] = $term->name;
}
$links = str_replace(' ', '-', $links);
$tax = join( " ", $links );
else :
$tax = '';
endif;
?>
<?php $infos = get_post_custom_values('_url'); ?>
<li class="<?php echo strtolower($tax); ?> all "> 如果你能帮我的话会很感激的。我已经搜索了很多,但没有找到任何解决方案。我是PHP新手。当然,我可以使用另一个过滤器插件,但我想找出问题所在,谢谢
发布于 2015-06-18 16:26:32
该问题是附加了一个带有#all的url,这意味着浏览器将查找id为all的元素。它在你的页面上找不到它,因为这个id.Hence不存在任何元素,点击几个链接后浏览器就会崩溃。
仅供参考,具有id的元素如下所示:
<div id="someelement" class="not the same thing as id" >content</div>
<div id="anotherelement" class="someelement" >content</div>在这种情况下,如果您将带有此元素的页面的url附加到带有#someelement的页面上,则浏览器将专注于第一个元素。这不会查找类为'someelement‘的元素。
如果要传递查询参数,则需要使用?products=all&etc格式。但是我认为你想要做的实际上是重定向到一个只显示所选术语的页面?在您的href中使用/term。
此外,你会在product_category上得到404,以及你在页面上的任何术语。问题的一部分是您使用的是$term->name而不是$term->slug,这可能会有所不同。创建分类法时是否重置了固定链接?另请检查此处所述的设置:
https://codex.wordpress.org/Function_Reference/register_taxonomy
默认情况下,WP会在taxonomy-teram.php和归档页面上创建一个循环,您运行的循环是第二个db请求和循环,因此这会增加服务器响应时间。使用pre_get_posts挂钩
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
https://stackoverflow.com/questions/30901133
复制相似问题