tripled
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkHi,
Pearhaps i don’t understand this magento plugin… but i think you use a magento plugin who connect to your wordpress database, and display your worpdress posts… but your CMS is MAGENTO and not WORDPRESS, you should go to see the api doc for your plugin : plugin doc
or here : magento pluginBest regards
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkThis code is for the MAGENTO CMS …. displaying-a-list-of-wordpress-recent-posts-in-magento
The problem is that i think it dont use the same api…
You should post on magento forum…
For wordpress you have to understand the loop
Good luck
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkWTF you use WORDPRESS CMS or MAGENTO CMS ?
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkI works for you now ?
or it’s not resolved ?Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkHi,
I think your problem is that you have 2 links…
The first is
<a>getPermalink() ?>">...</a>
And the second link is inside the first one ! :
<a>getPermalink() ?>">...<?php the_content('Read more...'); ?>...</a>
I must not have a link include in an other link !
For your information i do that in my page :
<a class="entry-content produit <?php echo $class;?>" href="<?php the_permalink(); ?><?php if(isset($url)) echo $url;?>"> <div class="vendu" style="<?php echo $vendu_display;?>"></div> <div class="fadehover"> <?php echo wp_get_attachment_image(get_field('my_custom_field1'), 'produit-apercu', $icon, array('class'=>'apercu-noir-et-blanc') ); echo wp_get_attachment_image(get_field('my_custom_field2'), 'produit-apercu', $icon, array('class'=>'apercu') ); ?> </div> <ul> <?php $data = get_field('my_custom_field3'); if ($data):?> <li><h4><?php echo truncateHtml($data,28, '...', true); ?></h4></li> <?php endif; $taxonomies = get_the_terms(get_the_ID(),my_id); $brand = ""; if(!empty($taxonomies) && is_array($taxonomies)) { foreach($taxonomies as $t){ $brand = $t->name; break; } } $price = get_field(my_custom_field4); if ($brand && price ):?> <li class="brand-price"><?php echo $brand;?> - <?php echo price; ?> €<?php echo $loop->current_post;?></li> <?php endif; ?> </ul> </a>
Using this function :
/** * truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags * * @param string $text String to truncate. * @param integer $length Length of returned string, including ellipsis. * @param string $ending Ending to be appended to the trimmed string. * @param boolean $exact If false, $text will not be cut mid-word * @param boolean $considerHtml If true, HTML tags would be handled correctly * * @return string Trimmed string. */ function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } // splits all html-tags to scanable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = strlen($ending); $open_tags = array(); $truncate = ''; foreach ($lines as $line_matchings) { // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { // do nothing // if tag is a closing tag } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { // delete tag from $open_tags list $pos = array_search($tag_matchings[1], $open_tags); if ($pos !== false) { unset($open_tags[$pos]); } // if tag is an opening tag } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { // add tag to the beginning of $open_tags list array_unshift($open_tags, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); if ($total_length+$content_length> $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { if ($entity[1]+1-$entities_length <= $left) { $left--; $entities_length += strlen($entity[0]); } else { // no more characters left break; } } } $truncate .= substr($line_matchings[2], 0, $left+$entities_length); // maximum lenght is reached, so get off the loop break; } else { $truncate .= $line_matchings[2]; $total_length += $content_length; } // if the maximum length is reached, get off the loop if($total_length>= $length) { break; } } } else { if (strlen($text) <= $length) { return $text; } else { $truncate = substr($text, 0, $length - strlen($ending)); } } // if the words shouldn't be cut in the middle... if (!$exact) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } // add the defined ending to the text $truncate .= $ending; if($considerHtml) { // close all unclosed html-tags foreach ($open_tags as $tag) { $truncate .= '</' . $tag . '>'; } } return $truncate; }
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkHi,
before you answer me i found a solution and it’s like in your sample !
The small difference is that i have to check where i come form in order to search only in the taxonomy i just select. My problem was that some product could be in 2 taxonomy or more.
Here is my function code :
function generate_url($produit_type = null, $produit_marque = null, $prix = null, $produits = null, $search = false) { $url_query = "?"; $noEmpty = false; if(isset($produit_type)) { if($noEmpty) $url_query .= '&'; $url_query .= REWRITE_PRODUIT_TYPE . "=" . $produit_type; $noEmpty = true; } if(isset($produit_marque)) { if($noEmpty) $url_query .= '&'; $url_query .= REWRITE_PRODUIT_MARQUE . "=" . $produit_marque; $noEmpty = true; } if(isset($prix)) { if($noEmpty) $url_query .= '&'; $url_query .= REWRITE_PRODUIT_PRIX . "=" . $prix; $noEmpty = true; } if($search) { if($noEmpty) $url_query .= '&'; $url_query .= REWRITE_SEARCH . "=1"; } return $url_query; } function decompose_url() { $data = array(); // Dans tous les cas je récupère les produits dans les cookies if(isset($_COOKIE[REWRITE_PRODUITS]) && !empty($_COOKIE[REWRITE_PRODUITS])) { $data[REWRITE_PRODUITS] = str_replace('\\','', $_COOKIE[REWRITE_PRODUITS]); } if(isset($_GET[REWRITE_PRODUIT_TYPE]) && !empty($_GET[REWRITE_PRODUIT_TYPE])) $data[REWRITE_PRODUIT_TYPE] = array( 'taxonomy' => 'produit_type', 'field' => 'slug', 'terms' => $_GET[REWRITE_PRODUIT_TYPE] ); if(isset($_GET[REWRITE_PRODUIT_MARQUE]) && !empty($_GET[REWRITE_PRODUIT_MARQUE])) $data[REWRITE_PRODUIT_MARQUE] = array( 'taxonomy' => 'produit_marque', 'field' => 'slug', 'terms' => $_GET[REWRITE_PRODUIT_MARQUE] ); if(isset($_GET[REWRITE_PRODUIT_PRIX]) && !empty($_GET[REWRITE_PRODUIT_PRIX])) $data[REWRITE_PRODUIT_PRIX] = $_GET[REWRITE_PRODUIT_PRIX]; if(isset($_GET[REWRITE_SEARCH]) && !empty($_GET[REWRITE_SEARCH]) && ($_GET[REWRITE_SEARCH]==1)) $data[REWRITE_SEARCH] = 1; // echo "<pre>"; // print_r($data); // echo "</pre>"; return $data; } /** * Génère la requete de taxonomie à partir de l'url * @return taxquery */ function get_query_args_from_url() { $data = decompose_url(); if(isset($data[REWRITE_SEARCH])) $search = $data[REWRITE_SEARCH]; if(isset($data[REWRITE_PRODUIT_TYPE])) $type = $data[REWRITE_PRODUIT_TYPE]; if(isset($data[REWRITE_PRODUIT_MARQUE])) $marque = $data[REWRITE_PRODUIT_MARQUE]; if(isset($data[REWRITE_PRODUIT_PRIX])) $prix = $data[REWRITE_PRODUIT_PRIX]; // SI ON VIENT DE LA RECHERCHE if(isset($search)) { $meta_query = array(); if( isset($type) && $type['terms']!=ALL_CATEGORIE) { $query_args['produit_type'] = $type['terms']; $searchArgs[REWRITE_PRODUIT_TYPE] = $type['terms']; } if(isset($marque) && $marque['terms']!=ALL_CATEGORIE) { $query_args['produit_marque'] = $marque['terms']; $searchArgs[REWRITE_PRODUIT_MARQUE] = $marque['terms']; } if(isset($prix) && $prix!=ALL_CATEGORIE && preg_match(PATTERN_PRODUIT_PRIX, $prix)) { $searchArgs[REWRITE_PRODUIT_PRIX] = $prix; $expprix = explode("-", $prix['terms']); if(count($expprix)>1) { array_push($meta_query, array( 'key' => 'produit_prix', 'value' => $expprix, 'compare' => 'BETWEEN', 'type' => 'NUMERIC' )); } else { array_push($meta_query, array( 'key' => 'produit_prix', 'value' => $prix, 'compare' => '>=', 'type' => 'NUMERIC' )); } } $query_args['orderby'] = 'produit_prix'; $query_args['order'] = 'ASC'; $query_args['post_type'] = 'produit'; $query_args['post__not_in'] = array(get_the_ID()); $query_args['hide_empty'] = '0'; if(isset($meta_query) && is_array($meta_query) && count($meta_query)>0) $query_args['meta_query'] = $meta_query; } // SINON ON VIENT DES AUTRES PAGES else { $tax_query = array(); if( isset($marque) && isset($type)) $tax_query = array( 'relation' => 'AND', $type, $marque ); else if(isset($type)) $tax_query = array($type); else if(isset($marque)) $tax_query = array($marque); $query_args = array( 'post_type' => 'produit', 'post__not_in' => array(get_the_ID()), 'posts_per_page' => 5, 'orderby' => 'rand', 'tax_query' => $tax_query ); } return $query_args; } /** * Génrère le lien de retour à la liste de produit de départ */ function get_back_to_list_link() { $data = decompose_url(); // echo "<pre>"; // print_r($query_args); // echo "</pre>"; if(isset($data[REWRITE_SEARCH])) $search = $data[REWRITE_SEARCH]; if(isset($data[REWRITE_PRODUIT_TYPE])) $type = $data[REWRITE_PRODUIT_TYPE]; if(isset($data[REWRITE_PRODUIT_MARQUE])) $marque = $data[REWRITE_PRODUIT_MARQUE]; if(isset($data[REWRITE_PRODUIT_PRIX])) $prix = $data[REWRITE_PRODUIT_PRIX]; if(isset($data[REWRITE_PRODUITS])) $produits = $data[REWRITE_PRODUITS]; // On vient de la page de recherche if($search) { //TODO: GERER LE RETOUR A LA PAGE DE RECHERCHE //?deco-industrielle=table&marque=tolix&prix=500-999&produit_search=1&submit=? $search_url = '?'; if(isset($type)) $search_url .= REWRITE_PRODUIT_TYPE . '=' . $type['terms']; if(isset($marque)) { if(strlen($search_url)>2) $search_url .= '&'; $search_url .= REWRITE_PRODUIT_MARQUE . '=' . $marque['terms']; } if(isset($prix)) { if(strlen($search_url)>2) $search_url .= '&'; $search_url .= REWRITE_PRODUIT_PRIX . '=' . $prix; } return site_url('/' . $search_url . REWRITE_SEARCH_FIN, 'http'); } // Si on vient d'une taxonomy particulière else if(isset($type) || isset($marque)) { if(isset($type)) return site_url('/' . REWRITE_PRODUIT_TYPE . '/' . $type['terms'], 'http'); if(isset($marque)) return site_url('/' . REWRITE_PRODUIT_MARQUE . '/' . $marque['terms'], 'http'); } // Si on vient des autres pages else { return home_url(); } } /** * Génère un tableau contenant l'élément précédent et/ou le suivant * @return multitype:string */ function get_nav_produit_links() { $current_produit_id = get_the_ID(); $data = decompose_url(); // echo "<pre>"; // print_r($data); // echo "</pre>"; if(isset($data[REWRITE_PRODUIT_TYPE])) $type = $data[REWRITE_PRODUIT_TYPE]; if(isset($data[REWRITE_PRODUIT_MARQUE])) $marque = $data[REWRITE_PRODUIT_MARQUE]; if(isset($data[REWRITE_PRODUIT_PRIX])) $prix = $data[REWRITE_PRODUIT_PRIX]; if(isset($data[REWRITE_PRODUITS])) $produits = $data[REWRITE_PRODUITS]; if(isset($data[REWRITE_SEARCH])) $search = $data[REWRITE_SEARCH]; $produits_copy = $produits; $liens = array(); $nbProduits = 0; $compteur = 0; $previous = -1; $current = -1; $next = -1; $current_post_find = false; if($current_produit_id!=null && $produits_copy!=null && is_serialized($produits_copy)) { $produits_copy = maybe_unserialize($produits_copy); if(is_array($produits_copy)) { $nbProduits = count($produits_copy); foreach ($produits_copy as $produit_id) { if(preg_match(PATTERN_PRODUIT_ID, $produit_id)) { if(!$current_post_find) { if($compteur==0) $previous = -1; else $previous = $current; $current = $produit_id; }else { if($compteur==($nbProduits)) $next = -1; else $next = $produit_id; } // Le post suivant vient d'être récupéré, on s'arrête. if($current_post_find) break; // Si on trouve l'id du post courant on s'arrête au prochain tour if($current_produit_id==$produit_id) $current_post_find = true; } $compteur++; } $link = (!isset($url_query))?generate_url($type['terms'], $marque['terms'], $prix, $produits, $search):''; if($previous!=-1) $liens['previous'] = '<a href="' . get_permalink($previous) . $link . '" ><span class="meta-nav" title="' . get_the_title($previous) . '"> </span></a>'; if($next!=-1) $liens['next'] = '<a href="' . get_permalink($next) . $link . '" ><span class="meta-nav" title="' . get_the_title($next) . '"> </span></a>'; } } return $liens; }
Thanks for your help
Forum: Developing with WordPress
In reply to: Multiple taxonomy with next_post_linkI really need help…
Did someone have a idea ?