我有一个类别dropdown1(ID为#blogcat
),该类别过滤了wordpress的博客帖子,这是默认功能。
我还有另一个自定义类型下拉列表(ID:#blogarticletype
)。
要求是:
考虑博客:
Blog 4
,属于类别Category 1
,并键入abc
Blog 5
,属于类别Category 1
,并键入xyz
这仅适用于dd类别
如果我从第一个下拉列表(即类别下拉列表)中选择了类别1,它将过滤掉Blog4和Blog5-http://example.com/index.php/blog/category1
这仅适用于文章类型dd: http://example.com/index.php/blog/?article_type=xyz
问题在这里。 http://example.com/index.php/blog/category1/?article_type=xyz
如果我再次从第二个下拉列表(即键入下拉列表)中选择xyz
,则应该只给我Blog5-
如何在Javascript下拉菜单中实现条件过滤器
两个过滤器都是分开工作的,即)
如果我从第1个dd中选择值,它会给出正确的过滤器,并且在第2个dd中相同
问题是当我尝试做儿童过滤器或第二级过滤器时
下面是代码
第一个下拉列表
jQuery('#blogcat').on('change', function() {
var baseurl ='<?php echo Mage::getBlockSingleton('wordpress/homepage')->getBlogHomepageUrl(); ?>'
var baseurl_events ='<?php echo Mage::getBaseUrl(); ?>events'
var category_slug = jQuery(this).val();
if(category_slug == 'events'){
var categories_redirect = baseurl_events;
jQuery( location ).attr("href", baseurl_events);
}else{
var categories_redirect = baseurl + category_slug;
jQuery( location ).attr("href", categories_redirect);
}
});
第二个下拉
jQuery('#blogarticletype').on('change', function() {
var baseurl ='<?php echo Mage::getBlockSingleton('wordpress/homepage')->getBlogHomepageUrl(); ?>'
var baseurl_events ='<?php echo Mage::getBaseUrl(); ?>events'
var baseurl_glossary ='<?php echo Mage::getBaseUrl(); ?>glossary'
var baseurl_catalogs ='<?php echo Mage::getBaseUrl(); ?>catalogs'
var category_slug = jQuery('#blogcat').val();
var article_slug = jQuery(this).val();
if(article_slug == 'events'){
var categories_redirect = baseurl_events;
jQuery( location ).attr("href", baseurl_events);
}
else if(article_slug == 'glossary'){
var categories_redirect = baseurl_glossary;
jQuery( location ).attr("href", baseurl_glossary);
}
else if(article_slug == 'catalogs'){
var categories_redirect = baseurl_catalogs;
jQuery( location ).attr("href", baseurl_catalogs);
}
else if(article_slug == null || article_slug == ''){
var categories_redirect = baseurl;
jQuery( location ).attr("href", baseurl);
}
else{
var redirect_url = baseurl+category_slug+'?article_type='+article_slug;
alert(redirect_url);
jQuery( location ).attr("href", redirect_url);
}
});
有关我的自定义下拉过滤器如何工作的代码-下面更新的magento代码。
Fishpig \ Wordpress \ Block \ Post \ List.php
protected function _getPostCollection()
{
//RAMD-641: Custom query to get the Article Filter types
$artical_type = Mage::app()->getRequest()->getParam('article_type');
if (is_null($this->_postCollection) && $this->getWrapperBlock()) {
$this->_postCollection = $this->getWrapperBlock()->getPostCollection();
if ($this->_postCollection) {
if ($this->getPostType()) {
$this->_postCollection->addPostTypeFilter($this->getPostType());
if(!empty($artical_type)) {
$posttypevalue = Mage::helper('wordpress')->getPostMetaData();
if(!empty($posttypevalue)) {
$this->_postCollection = $this->_postCollection->addFieldToFilter('ID',array('in' => $posttypevalue));
}
}
}
if ($this->getPagerBlock()) {
$this->getPagerBlock()->setCollection($this->_postCollection);
}
}
}
return $this->_postCollection;
}
Helper / Data.php
public function getPostMetaData()
{
$artical_type = Mage::app()->getRequest()->getParam('article_type');
try{
if(!empty($artical_type)) {
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('new_db');
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$query = 'SELECT b.post_id FROM wp_posts AS a, wp_postmeta AS b WHERE a.ID=b.post_id AND b.meta_key="type" AND a.post_status="publish"';
$query .= " AND b.meta_value LIKE '%".$artical_type."%' ORDER BY a.post_date DESC";
//var_dump($query);
$post_ids = $readConnection->fetchAll($query);
if(!empty($post_ids)) {
$_post_id_array = array();
foreach($post_ids as $post) {
$_post_id_array[] = $post['post_id'];
}
$_post_id_array = array_unique($_post_id_array);
return $_post_id_array;
}
}
return false;
} catch (Exception $e) {
return false;
}
}