is it possible to track the route that the user took to get to a page ?
say that i have a post that have 2 different taxonomies
taxonomy 1 = make
taxonomy 2 = color
i want to create a different layout for each route
this is my current hierarchy:
Mercedes -> blue -> car - the user gets template 1 (single-car.php)
blue -> Mercedes -> car - the user gets template 1 (single-car.php)
this is what i want
Mercedes -> blue -> car - the user will get template 1 (single-car_by_make.php)
blue -> Mercedes -> car - the user will get template 2 (single-car_by_color.php)
is that possible without using extra query-strings ?
I am not writing actual code. But I just giving idea how to do it.
use the the following logic in the your single-car.php file
if(taxonomy == make )
get_template_part( 'single-car_by_make' );
if(taxonomy == color)
get_template_part( 'single-car_by_color' );
I hope It will help you.
Related
My e-commerce inventory mainly contains street signs which i added some custom code to display the dimensions (H x W x L) of my signs in single product
However I have a few jackets that don't require dimensions.
I cannot find what fields or an example of an IF statement that will only let me display certain fields for a specific category.
I assume that dimensions is set in product data.
$meta = get_postmeta($post_id);
if ($meta['_width'][0] && $meta['_length'][0] && $meta['_height'][0]) {
//show the dimensions
}
I currently have a piece of code which will grab a product title, description, and price and for that it works great. However, I also need it to get the image URL which is where my dilemma is. I tried using a xpath inside the loop I have at the bottom and it lists out ALL the images that are equal to 220 on EVERY product which I dont want at all. So basically I get something like this....
product 1 Title here
product 1 Description here
product 1 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
product 2 Title here
product 2 Description here
product 2 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
Where as I obviously want product 1 to just have http://www.test.com/product1.jpg and product 2 to have http://www.test.com/product2.jpg etc, etc. The images are just in a div tag with no class or ID hence why I didnt just easily put them into a css selector. Im really new to ruby/nokogiri so any help would be great.
require 'nokogiri'
require 'open-uri'
url = "http://thewebsitehere"
data = Nokogiri::HTML(open(url))
products = data.css('.item')
products.each do |product|
puts product.at_css('.vproduct_list_title').text.strip
puts product.at_css('.vproduct_list_descr').text.strip
puts product.at_css('.price-value').text.strip
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
end
Try changing:
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
to:
puts product.xpath('.//img[#width = 220]/#src').map {|a| a.value }
The point of the '.' there is to say you want all images that are children of the current node (e.g. so you're not peeking at product 2's images).
File#basename will return only the filename:
File.basename('http://www.test.com/product4.jpg')
#=> "product4.jpg"
So you probably want something like this:
puts product.xpath('//img[#width = 220]/#src').map {|a| File.basename(a.value) }
I have this array in a Drupal 7 installation, it outupts the term list that belongs to a specific vocabulary id:
<?php print render($content['taxonomy_vocabulary_3']); ?>
Now, what this does it outputs the result in a list, I would like to output it in a comma separated line.
Now, I suppose that I could do that with a foreach statement?
I´ve tried this, after reading the documentation, but it outputted nothing:
foreach($taxonomy_vocabulary_3 as $id=>$tag) {
echo "$tag, " ;
}
I´ve looked into what the Devel module told me about that array, and it showed me this:
taxonomy_vocabulary_3 (Array, 1 element)
und (Array, 2 elements)
0 (Array, 1 element)
tid (String, 3 characters ) 141
1 (Array, 1 element)
tid (String, 3 characters ) 320
But as you can see it shows the term id in each case, and not the term name...
What do you suggest? Thanks!!
You can load the term and then print it's title.
foreach($vocabulary as $tid) {
$term = taxonomy_term_load($tid);
// print whatever you want from this object.
print $term->title . ', ';
}
taxonomy_term_load
What you got is a build array - so that means that
$content['taxonomy_vocabulary_3']['#theme']
will be the theme function used to render the vocabulary. If you want to change the output you have two good solutions.
override the standard theme function in your theme - this will alter the output of all the calls to that theme function - in this case how all vocabularies is rendered.
Change the #theme value to a theme function of your liking - this could be a custom theme function you define in your theme.
For help on how to render the terms, you can take a look at how the original theme function is implemented - you can look it up at the Drupal API documentation.
I try to achieve the following layout with Wordpress 3.2.1:
---> ID 4 (Record 2, 3rd Attempt)
--> ID 3 (Record 2, 2nd Attempt)
-> ID 2 (Record 2, 1st Attempt)
--> ID 5 (Record 1, 2nd Attempt)
-> ID 1 (Record 1, 1st Attempt)
Every line represents a page and on the Backend the page hierarchy looks like that:
-> ID 1
--> ID 5
-> ID 2
--> ID 3
---> ID 4
I'm sorry I prepared a nice illustration but I'm not yet allowed to post images. So, to explain it a bit further: I try to build a list of records and as soon as one of the records gets broken, it will shift to the right and on top of it the newest record attempt appears.
Ok, so first question: How do I have to set up query_posts to recursively get all children? The following code only returns page 3 but not 4:
<?php query_posts(array('post_parent' => 2, 'post_type' => 'page')); ?>
And second question: Does anyone know a better/simpler/sexier (Wordpress) solution for what I try to achieve?
try
$child_pages = get_pages('child_of=2');
you can look it up in the WP Codex here: http://codex.wordpress.org/Function_Reference/get_pages
I have 2 level categories like this:
paintings
- car
- cat
- dog
other
- other1
- other2
...
Now I've many posts in each sub-category.
My goal is get the next post and previous post from the current post in current main category.
For example : I've a post name : "a good car" in car category. Then I've a post name : "A big cat " in cat category . Then I've a post name : "a small dog " in dog category.
Now in the "a big cat" post , I'm trying to get the 'a small dog' post as next post and the 'a good car' as prev post.
I'm used :
codex.wordpress.org/Function_Reference/get_next_post
and :
codex.wordpress.org/Function_Reference/get_previous_post
but they still can't get the right post for me.
If I try with :
get_previous_post( false, '' )
I will get the previous post but not in painting category.
Also If I try with:
get_previous_post( true, '' )
I will get only the previous post in the current category , not the painting category.
Anyone can help me ? Thank you!
First, I would be sure that your "cat" paintings belong to both the "cat" and "paintings" categories. By default, I believe, the WordPress PREV/NEXT functions will work the way you're explaining.
i would expect this to work for you, provided your items are included in both the sub and main categories:
<?php previous_post_link('%link', 'Previous in category', TRUE); ?>
More details:
http://codex.wordpress.org/Template_Tags/previous_post_link and
http://codex.wordpress.org/Template_Tags/next_post_link