Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to query a specific portfolio Image in an image tag
- This topic has 6 replies, 2 voices, and was last updated 9 years, 6 months ago by Toon61.
-
AuthorPosts
-
May 20, 2015 at 11:37 am #152929Toon61Member
Hi all,
I'm struggling with this one.
In some of the available containers on a regular page I want to show a specific image (featured image) from one of the available portfolio categories.
In the portfolio I have categories like 'Styling' or 'Kids'.
The portfolio has a lot of posts which I categorise with one of the categories ( 'Styling', 'Kids' etc.).Now comes the tricky part.
I've created a page with a static grid (looks like masonry) (see: http://mgf.woohoodesign.nl/styling/)
Now I want the available spaces to be filled with an image I retrieve from one of the posts in one of the portfolio-categories.
I figured out how to show the featured image of the page itself:
echo '<img source="' . genesis_get_image( array( 'size' => 'medium' ) ) . '"/>';
But I want something like this (warning: this is not correct syntax !!!):
echo '<img />' .get_post_type_archive( 'portfolio' ) & get_post_type_category( 'styling') & query_posts( 'p=3' ) & genesis_get_image( 'size' => 'medium' ) ;'
In other words:
I want to target the portfolio Custom Type (which is Portfolio) + Category (which is Styling) + specific Post (which might be post 3 with id 112) and then show the featured image.This looks like standard WordPress logic, but I cannot figure out how to do this.
Any help is appreciated
http://mgf.woohoodesign.nl/styling/May 20, 2015 at 2:17 pm #152956Brad DaltonParticipantMay 21, 2015 at 1:10 am #153068Toon61MemberHi Brad,
Pretty easy indeed for a more experienced coder I guess. But I'm afraid I am not such a coder.
Nevertheless, I'll look into it and see if I can get it working for me.Thanks for your reply.
May 21, 2015 at 2:08 am #153070Brad DaltonParticipantHere's a freebie http://wpsites.net/wordpress-tips/fetch-dsiplay-a-list-of-popular-posts-by-comment-count/
What you need to do is get the right parameters for your CPT category.
And add the post thumbnail
May 21, 2015 at 9:56 am #153103Toon61MemberHi Brad,
Thank you for this freebie, really appreciate that.
In the meantime I've been working my way through the magic and power of wp-query (and a lot more PHP-stuff for that matter), and looking into the different php files from some of the StudioPress Themes I own.
And I feel I'm getting more and more into it.
Actually, it is quite fun trying to be a coder (as long as I don't get those completely blank pages...)May 21, 2015 at 7:28 pm #153175Brad DaltonParticipantGood luck with that as i know its a bit complicated but you'll learn a lot from having a go yourself.
June 13, 2015 at 10:02 am #156097Toon61MemberOk,
It's been a while since I started this topic, but I want you all to know I've figured it all out.
Just as Brad said it is not that difficult, in fact it is basic WordPress Query stuff.
The thing to watch out for is that the Genesis templates are a bit different constructed than regular WP templates.
I found that out by 'copy-paste' a few WordPress examples, and got the awfull 'White Screen' (most of the time this is due to the fact that the PHP code is not valid). And when copying generic PHP examples in a Genesis template, well, you get a PHP error because Genesis does use the<?php
opening at the beginning of a template, but closes the template with a function(?):genesis();
and not with a closing?>
like the standard WordPress templates do.
So when you paste in a bit of WordPress PHP code, make sure you leave out the closing?>
, because Genesis handles this with it's special function.
Another thing I came across was the fact that I use the Portfolio Post Type plugin to create the Portfolio pages.
When registering a Custom Post Type the WordPress way, you can query this by using'post_type' => 'portfolio'; 'category' => 'styling';
In this case the 'category' let's you query specific portfolio categories you have created.
But the Portfolio Post Type (that also creates a Custom Post Type 'portfolio') uses this syntax:
'post_type' => 'portfolio'; 'portfolio_category' => 'styling';
As you can see, it doesn't use the generic WP 'category' but instead it's own 'portfolio_category'. Not a big problem, but it took me a few hours before I found this one out.
After all, this is how a part of my queries look like:
// WP_Query arguments $args = array ( 'post_type' => 'portfolio', 'portfolio_category' => $name , 'pagination' => false, 'order' => 'ASC', 'offset' => 0, 'posts_per_page' => 1 ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); the_post_thumbnail() ; } } else { echo '<p>No image found</p>'; } wp_reset_postdata();
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.