Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Filterable Portfolio WordPress

  • SOLVED

Over the past weeks I been building a site and have used the guide by Rafael Angeline :: http://wp.tutsplus.com/tutorials/creating-a-filterable-portfolio-with-wordpress-and-jquery/

I have everything working here :: http://globalicn.com/preview/regions/europe/

But I am trying to go two steps further:
1) I would love for the loop to show the posts by category (country) and list them alphabetically. Or how could I have the page display the posts by country instead of post title name.

2) The URL button that links to their website. Some of the directories don´t have a website. I thought I had a code that would check if the metabox had data and display and if there wasn´t any data, to leave the button to not show. If I deselect the tag Souther-Europe then the code I have in their works, and does not display information. But with the tag selected it shows the website button with this for URL http:///

The code for the page I am using is here: http://pastebin.com/8taYL6Da

I been trying for the past few days to figure these questions out! Thanks for any feedback!

Answers (1)

2012-12-28

Kyle answers:

For #2 you may want to try to change this line

if ($infos)

to this,

if (!empty($infos))

let me know if that works. If it does not it is likely because the _url field is still storing some generic placeholder, so when you check for it being empty it is misfiring. Can you check the custom field that is meant to be blank and confirm there is nothing there?


Kyle comments:

For the loop, you would have to restructure how you execute the query because WP cannot order_by category. So you will have to retrieve each category you want, in the right order, then display them.

This is a boiled down starting point:


$cat_args=array(
//Category Arguments
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
//Post arguments
);
$posts=get_posts($args);
if ($posts) {
//Category Heading Output if a post is present
foreach($posts as $post) {
setup_postdata($post);
//Output for each found post
}
}
}
?>


ntarantino comments:

Ok, gave that a try, it seems to break the page though. I did check the post and there isn´t anything in the custom field...

the functions for the Europe page is here: http://pastebin.com/fmftYCT4


Kyle comments:

Which part broke the page?


ntarantino comments:

for #1 would it be easier to assign a custom value which would be the country then

query_posts('post_type=europe&meta_key=country_name&orderby=meta_value&order=ASC');


ntarantino comments:

sorry about that, when I added


<?php if (!empty($infos) { ?>
<div class="color-buttons color-button-blue website"><a href="http://<?php echo $infos[0]; ?>" target="_blank">Website →</a></div>
<?php } ?>


Kyle comments:

Sure you can order by meta values, but you will have to go through each one and put the country name in. You're good with custom fields apparently, so it would be easy, just time consuming if you have lots of pages :) . When ordering by meta values, it will sort alphabetically by default.


Kyle comments:

Check this line

<?php if (!empty($infos) { ?>

should be this (missing a parenthesis) :

<?php if (!empty($infos)) { ?>


ntarantino comments:

Ok, page isn´t broke! Excellent! Still getting the same issue with http:/// on listings that dont have a website. Check the 4th to bottom where contacts are Terry Hoggard... http://globalicn.com/preview/regions/europe/#all

Not sure if I mentioned, if I deselect the tag which sets the portfolio filter then this whole thing actually works, its just went there is a tag set it gives data no matter if the field is blank or not...

At this point, if the meta option can work, I think it would easier then setting the categories. I understood the logic of the code but I would of been stumped after that :)


Kyle comments:

Okay, well for the first one the best troubleshoot idea may be to simply echo _url next to each button to see what is getting put out for each link, so you know what you are working with, from there it will be easier to find why the !empty is still picking up something.

I'm not quite sure what you mean by 'deselect the tag which sets the portfolio filter' but that does sound like the source of the problem.. somehow

That's fine, its okay to keep up with what you are comfortable with. If you need help with the category code tho I can help


ntarantino comments:

Sorry, I am such a visual learner sometimes... when you say "simply echo _url next to each button"

What exactly am I doing there? In the code I had before
<?php if (!empty($infos)) { ?>
<div class="color-buttons color-button-blue website"><a href="http://<?php echo $infos[0]; ?>" target="_blank">Website →</a></div>
<?php } ?>


Do I put it in replacement in that?


Kyle comments:

My mistake, yeah I'm the same way. Replace this:

<?php if ($infos) { ?>
<div class="color-buttons color-button-blue website"><a href="http://<?php echo $infos[0]; ?>" target="_blank">Website →</a></div>
<?php } ?>

with this:

<?php if ($infos) { ?>
<div class="color-buttons color-button-blue website"><a href="http://<?php echo $infos[0]; ?>" target="_blank">Website →</a><?php echo $infos; ?></div>
<?php } ?>


ntarantino comments:

Ok, basically it´s just pushing the data ARRAY after each link... make anything out of that?

The tutorial I followed to make this filter - http://wp.tutsplus.com/tutorials/creating-a-filterable-portfolio-with-wordpress-and-jquery/

So it was set that when you gave a post a tag, that would be the filtered sections... so I give a post and say wether it´s in:
Central Europe, Western, Southern etc...

When I do set the tag, this system doesn´t work, but then again when I just checked it now, it still show the button. So what I was seeing before isn´t even working now! :(


Kyle comments:

Ah I see, I believe that array output is the problem. Try switching get_post_custom_values to get_post_meta

so this:

<?php $infos = get_post_custom_values('_url'); ?>

becomes

<?php $infos = get_post_meta($post->ID, '_url', true); ?>



Kyle comments:

Did something new break?


ntarantino comments:

Wow! Stellar! It worked, now only displaying link if there is something there. I feel so much better already!

Ok, so help me understand the query part, so how I have it set now is category (region) then sub category (nations)

Would I have to write a query that includes all nations, or how would that go about for the Europe page?


Kyle comments:

Okay, the subcategory basically adds a step in the ladder between posts and categories.So if you wanted to do Europe, you could basically do Get category (i.e. region), then the Foreach becomes for each child (sub categories, i.e. nations), do posts.

Likewise if you wanted to make a huge list you could include two Foreach-es. Something like Foreach Category, get children, and foreach child do posts.


ntarantino comments:

I do believe this is where my knowledges really becomes blurred. What can I do to have you help me write this? I can easily work it for the other regions once I see how it works.

Like you see already, I just want it to work like that but you see the list by countries, starting with Albania, Austria and so on
- content (address info)
- meta box (URL)

If you feel my 20 is spent just say so, this has been something I have racked my head over for days and came up with nothing.


Kyle comments:

Are you just looking to list the link to each nation?

So list the links to each nation's page of each region


ntarantino comments:

No, we don´t need to link, when you go here, it shows all the listings... http://globalicn.com/preview/regions/europe/#all

Currently, the loop is

$loop = new WP_Query(array('post_type' => 'northern', 'posts_per_page' => -1, 'order' => 'asc'));

<strong>Organized by Post Title, so the listing is:</strong>
All Nations Christian Fellowship - SPAIN
Bratislava International Fellowship - SLOVAKIA
Brussels Christian Center - BELGIUM
Bucharest International Church - ROMANIA

What I would like is to have the listing by country so the top 4 would be
International Protestant Assembly - <strong>Albania</strong>
Vienna Christian Center - <strong>Austria</strong>
Brussels Christian Center - <strong>Belgium</strong>
The Lighthouse Centre - <strong>Belgium</strong>



Kyle comments:

This is definitely a rough draft, but this is a starting point.

$cat_args=array(
'orderby' => 'title',
);

$categories = get_categories($cat_args); //get all regions

foreach ($categories as $category){

$children = get_category_children($category) //for each region get all nations

foreach ($children as $child){

$post_args=array(
'showposts' => -1,
'category__in' => array($category->term_id),
'caller_get_posts'=>1 );

$posts=get_posts($post_args); //for each region get posts

if ($posts) { //make sure there are posts before output

foreach($posts as $post) {

setup_postdata($post);

//put your original content here

}
}
}
}


ntarantino comments:

Sorry for the delay, I was on the phone.

Ok, so I will need some help clarifying where this code goes. Since I was following that tutorial I don´t want to mess up the code that make the filterable search to run.

The code that is there now before the div wrapper is:

<?php
$terms = get_terms("tagportfolio");
$count = count($terms);
echo '<ul id="portfolio-filter">';
echo '<li><a href="#all" title="">All</a></li>';
if ( $count > 0 ){
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(' ', '-', $termname);
echo '<li><a href="#'.$termname.'" title="" rel="'.$termname.'">'.$term->name.'</a></li>';
}
}
echo "</ul>";
?>
<?php
$loop = new WP_Query(array('post_type' => 'europe', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'asc'));
$count = 0;
?>


Then the content is displayed in this code:


<?php $infos = get_post_meta($post->ID, '_url', true); ?>
<li class="portfolio-item <?php echo strtolower($tax); ?> all">
<div style="margin:0 17px 0 0;"class="color-buttons color-button-black left"><a style="padding:3px 6px 3px; font-size:8px;" href="#"> <?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?> </a></div><hr class="churches">
<h3 class="church"><?php the_title(); ?></h3>
<?php the_content(); ?></br class="clear">
<?php if (!empty($infos)) { ?>
<div class="color-buttons color-button-blue website"><a href="http://<?php echo $infos[0]; ?>" target="_blank">Website →</a></div>
<?php } ?>
</li>
<?php endwhile; else: ?>
<li class="error-not-found">Sorry, no portfolio entries for while.</li>
<?php endif; ?>
</ul>


ntarantino comments:

Yesterday, when we looked over this, I missed one small detail :) When we changed this:
<?php $infos = get_post_meta($post->ID, '_url', true); ?>

It only display the first letter of the metabox... so all fields only show "w" the first part www.website.com


ntarantino comments:

Maybe I solved myself :) Took the same code we replace up to

so replace this

<?php echo $infos[0]; ?>

with

<?php echo get_post_meta($post->ID,'_url',TRUE); ?>