I want to ask the Portfolio Page Template to exclude one portfolio category from being displayed in the portfolio. So when it shows the categories: All | Travel | Macro | Archive, etc. I need to exclude Archive (slug archive) from both the top filter and from the All feed, because I want to place that on a separate page called Archive.
How do I do that?
<?php
/*
Template Name: Portfolio number 1
*/
?>
<?php get_header(); ?>
<div class="container">
<div id="homecontent">
<ul id="portfolio-filter" class="filter clearfix">
<li class="active">All</li>
<?php
// Get the taxonomy
$terms = get_terms('categories');
$term_list = '';
// set a count to the amount of categories in our taxonomy
$count = count($terms);
// set a count value to 0
$i=0;
// test if the count has any categories
if ($count > 0) {
// break each of the categories into individual elements
foreach ($terms as $term) {
// increase the count by 1
$i++;
// rewrite the output for each category
$term_list .= '<li>' . $term->name . '</li>';
// if count is equal to i then output blank
if ($count != $i)
{
$term_list .= '';
}
else
{
$term_list .= '';
}
}
// print out each of the categories in our new format
echo $term_list;
}
?>
</ul>
<div style="clear: both;"></div>
<ul id="portfolio-list" class="filterable-grid clearfix centerrow filter-posts">
<?php
// Set the page to be pagination
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
// Query Out Database
$wpbp = new WP_Query(array( 'post_type' => 'myportfoliotype', 'posts_per_page' =>'99', 'paged' => $paged ) );
?>
<?php
// Begin The Loop
if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post();
?>
<?php
// Get The Taxonomy 'Filter' Categories "categories"
$terms = get_the_terms( get_the_ID(), 'categories' );
?>
<?php
$large_image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' );
$large_image = $large_image[0];
$another_image_1 = get_post_meta($post->ID, 'themnific_image_1_url', true);
$video_input = get_post_meta($post->ID, 'themnific_video_url', true);
$price = get_post_meta($post->ID, 'themnific_item_price', true);
$ribbon = get_post_meta($post->ID, 'themnific_class', true);
?>
<li class="centerfourcol filter" data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->slug)). ' '; } ?>">
<?php get_template_part('/includes/folio-types/home_carousel'); ?>
</li>
<?php $count++; // Increase the count by 1 ?>
<?php endwhile; endif; // END the Wordpress Loop ?>
<?php wp_reset_query(); // Reset the Query Loop?>
</ul>
<?php
/*
* Download WP_PageNavi Plugin at: http://wordpress.org/extend/plugins/wp-pagenavi/
* Page Navigation Will Appear If Plugin Installed or Fall Back To Default Pagination
*/
if(function_exists('wp_pagenavi'))
{
wp_pagenavi(array( 'query' => $wpbp ) );
wp_reset_postdata(); // avoid errors further down the page
}
?>
<div style="clear: both;"></div>
</div><!-- #homecontent -->
</div>
<?php get_footer(); ?>
I found the answer, the code below only allows one categorie to be displayed in the portfolio.
‘tax_query’ => array( array( ‘taxonomy’ => ‘categories’, ‘field’ => ‘slug’, ‘terms’ => ‘archive’, ‘operator’ => ‘IN’) ),
Related
As we know, to display posts on wordpress we must use a loop. But in general, the loop used to display posts on wordpress is as follows
$query = new WP_Query( $args );
$query = $query->get_posts();
foreach ($query as $post) :
the_post();
endforeach;
the question is, how do I get $post[$i] so that the results I will get are as follows.
<!-- i want to print wordpress post like this format-->
<div class='grid'>
<div class='column'>
<!-- $i = 0 -->
<!-- start loop -->
<!-- print post -->
<span><?php echo $post[$i]->title; ?></span>
<!-- $i = $i + 3 -->
<!-- end loop -->
</div>
</div>
the concept is I want to display the first post based on the value of $i, then the next post based on the value of $i = $i + 3, so the final result will print $post[0], $post[3], $post[6], [...] , any suggestions?
sorry for my english, Thanks - Edwin.
This should be the solution to display your posts:
<?php
$posts = new WP_Query( $args );
if( $posts->have_posts() ) : //checks if query have posts
while( $posts->have_posts() ) : $posts->the_post();
if( $i % 3 == 0 ) : //every third post ?>
<div class='grid'>
<div class='column-<?php the_ID(); ?>'>
<span>the_title();</span>
</div>
</div>
<?php endif;
$i++;
endwhile;
else :
// if no posts
endif;
wp_reset_postdata();
?>
i got this answer from other question and other forum
$query = new WP_Query( array( 'post_type' => 'page' ) );
$posts = $query->posts;
foreach($posts as $post) {
// Do your stuff, e.g.
// echo $post->post_name;
}
and i make some change from the code to get my result
$query = new WP_Query();
$posts = $query->posts;
$i = 0;
foreach($posts as $post) {
// Do your stuff, e.g.
// echo $post[$i]->post_name;
$i = $i + 3;
}
I have a WP website with a portfolio section.
On portfolio page it shows project categories.
I would like to show only child categories of parent category with id=63.
This is the current code:
<?php $terms = get_the_terms( $post->ID , 'portfolio_category', 'string' ); ?>
<?php $num_of_terms = count($terms); ?>
<?php if($terms) { ?>
<div class="meta-column">
<strong class="caps"><?php esc_html_e( 'Artist', 'onioneye' ); ?><span class="colon">:</span></strong>
<span>
<?php
$i = 0;
foreach($terms as $term) {
if($i + 1 == $num_of_terms) {
echo esc_html($term -> name);
}
else {
echo esc_html($term -> name . ', ');
}
$i++;
}
?>
</span>
</div>
<?php } ?>
Could you try this:
$args = array('child_of' => 63);
$terms = get_categories( $args );
in place of this:
$terms = get_the_terms( $post->ID , 'portfolio_category', 'string' );
I'm trying to display a custom field I've made with Advanced Custom fields called Suffix after the child page title, I´m really confused of how to accomplish this.
I've pasted the code a friend helped me with below that lists pages and childpages below.
Is it possible to do this?
<?php
$pageID = $sub_field_3 = get_sub_field('page_id');
$page = get_post($pageID);
echo $page->post_title;
?>
<ul>
<?php
// use wp_list_pages to display parent and all child pages all generations (a tree with parent)
$parent = $sub_field_3 = get_sub_field('page_id');
$args=array(
'child_of' => $parent
);
$pages = get_pages($args);
if ($pages) {
$pageids = array();
foreach ($pages as $page) {
$pageids[]= $page->ID;
$suffix = get_field('suffix', $page->ID);
}
$args=array(
'title_li' => ' ',
'include' => ',' . implode(",", $pageids)
);
wp_list_pages($args);
}
?>
</ul>
Got it, this is how I got it to work.
Thanks, K.
<?php
$parent = $sub_field_3 = get_sub_field('page_id');
$args=array(
'child_of' => $parent
);
$pages = get_pages($args);
if($pages): ?>
<li>
<ul>
<?php foreach($pages as $page): ?>
<li class="">
<a href="<?php echo get_permalink($page->ID);?>">
<?php echo $page->post_title; ?>
<?php
$suffix = get_field('name_suffix', $page->ID);
if($name_suffix):
?>
<span class="suffix"><?php echo $name_suffix; ?></span>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endif; ?>
I'm to list categories with images in the sidebar this is how I do it (and it works) I do this because I've certain categories I do not want to display!
<?php $latests = new WP_Query('posts_per_page=2&ignore_sticky_posts=1&cat=12'); ?>
<?php echo get_cat_name(12); ?>
<?php while ($latests->have_posts()) : $latests->the_post(); ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('sidebarcat'); } ?>
<?php the_title(); ?>
<?php endwhile; wp_reset_postdata(); ?>
but I need to copy past that code for every single category... and all this code for only changing a number is a good practice I guess. Is there another way it could be done?
I've tried with a foreach but it seems to be wrong
<?php $latests = new WP_Query('posts_per_page=2&ignore_sticky_posts=1&cat=12'); ?>
<?php foreach($latests as $latest) :?>
<?php while ($latests->have_posts()) : $latests->the_post(); ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('sidebarcat'); } ?>
<?php the_title(); ?>
<?php endwhile; wp_reset_postdata(); ?>
<?php endforeach; ?>
Well, You can do it like this:
<ul>
<?php
$cat_args=array(
// 'include' => '3,6,9', // display only these categories
'exclude' => '3,6,9', // display all categories except categories 3,6,9
'orderby' => 'name', // the order
'order' => 'ASC' // asc or desc
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => 2, // how many posts you want to display
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<h3> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in: %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
foreach($posts as $post) {
setup_postdata($post);
?>
<li>
<div>
<div><?php if ( has_post_thumbnail() ) { the_post_thumbnail('sidebarcat'); } ?></div>
<div><?php the_title(); ?></div>
</div>
</li>
<?php
} // close foreach
} // close if
} // close foreach
?>
</ul>
The easiest way is like that
<?php wp_list_categories('orderby=name&exclude=3,5,9,16'); ?>
So, this will return you all the categories excluding the one you specified. After this, you can get the actual image you want for your categories and all.
Good Day.
I am using a theme that has a Portfolio. The portfolio currently displays all categories listed. How can I change it to display only certain categories ie. Design and Images?
Here is the code of the Portfolio Template Page
<?php
/*
Template Name: Portfolio page
*/
?>
<?php get_header(); ?>
<?php
global $wp_query;
$post = $wp_query->post;
$gogo_select_portfolio_cat = get_post_meta($post->ID, 'gogo_select_portfolio_cat', true);
$gogo_portfolio_items_order = get_post_meta($post->ID, 'gogo_portfolio_items_order', true);
$gogo_portfolio_text_no_posts = get_post_meta($post->ID, 'gogo_portfolio_text_no_posts', true);
$gogo_select_portfolio_template = get_post_meta($post->ID, 'gogo_select_portfolio_template', true);
$gogo_select_portfolio_sidebar_position = get_post_meta($post->ID, 'gogo_select_portfolio_sidebar_position', true);
?>
<div class="block clearfix">
<header class="box-headline">
<h4 class="main-headline"><?php the_title(); ?></h4>
</header>
<?php if ($gogo_select_portfolio_template=='portfolio-fourthcol') {
load_template(TEMPLATEPATH . '/lib/includes/portfolio/portfolio-4col.php');
} ?>
<?php if ($gogo_select_portfolio_template=='portfolio-threecol') {
load_template(TEMPLATEPATH . '/lib/includes/portfolio/portfolio-3col.php');
} ?>
<?php if ($gogo_select_portfolio_template=='portfolio-twocol') {
load_template(TEMPLATEPATH . '/lib/includes/portfolio/portfolio-2col.php');
} ?>
</div>
<?php get_footer();?>.
Portfolio-4col.php content:
<ul id="filterOptions" class="horizontal" data-option-key="filter">
<li><a class="selected" href="#filter" data-option-value="*">Show all</a></li>
<?php
$categories= get_categories('taxonomy=portfolio_cat&title_li=');
foreach ($categories as $category){ ?>
<li><?php echo $category->name;?></li>
<?php }?>
</ul>
<ul class="isotope-holder horizontal four-columns">
<?php rewind_posts(); ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array(
'post_type' => 'portfolio',
'posts_per_page' => -1,
'ignore_sticky_posts' => 1
)
);
$postcount = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post(); $postcount++;?>
<!--Retrieve posts meta from custom post types -->
<?php
$gogo_portfolio_short_desc = get_post_meta($post->ID, 'gogo_portfolio_short_desc', true);
$gogo_portfolio_video_url = get_post_meta($post->ID, 'gogo_portfolio_video_url', true);
$gogo_portfolio_custom_link = get_post_meta($post->ID, 'gogo_portfolio_custom_link', true);
$gogo_portfolio_display_image_link = get_post_meta($post->ID, 'gogo_portfolio_display_image_link', true);
$gogo_portfolio_display_article_link = get_post_meta($post->ID, 'gogo_portfolio_display_article_link', true);
$gogo_portfolio_display_external_link = get_post_meta($post->ID, 'gogo_portfolio_display_external_link', true); ?>
<li class="element <?php $terms = wp_get_post_terms($post->ID,'portfolio_cat'); foreach ($terms as $term) { echo ' ' .$term->slug. ' '; } ?>">
<div class="view view-sixth">
<?php if (has_post_thumbnail()) { ?>
<figure>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w=218&h=200&zc=1&q=100&s=1" alt="'.get_the_title().'" />';?>
</figure>
<?php } ?>
<div class="mask">
<header class="box-headline">
<?php echo '<h4>'; echo ''.get_the_title().''; echo '</h4>'; ?>
</header>
<div class="content">
<p><?php echo $gogo_portfolio_short_desc; ?></p>
<span>Read More »</span>
</div>
</div>
</div>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</ul>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(window).load(function() {
var $jcontainer = $j('ul.isotope-holder');
$jcontainer.isotope({
itemSelector : '.element',
resizable: false, // disable normal resizing
// set columnWidth to a percentage of container width
masonry: { columnWidth: $jcontainer.width() / 4 }
});
// update columnWidth on window resize
$j(window).smartresize(function(){
$jcontainer.isotope({
// update columnWidth to a percentage of container width
masonry: { columnWidth: $jcontainer.width() / 4}
});
});
var $joptionSets = $j('#filterOptions'),
$joptionLinks = $joptionSets.find('a');
$joptionLinks.click(function(){
var $jthis = $j(this);
// don't proceed if already selected
if ( $jthis.hasClass('selected') ) {
return false;
}
var $joptionSet = $jthis.parents('#filterOptions');
$joptionSet.find('.selected').removeClass('selected');
$jthis.addClass('selected');
// make option object dynamically, i.e. { filter: '.my-filter-class' }
var options = {},
key = $joptionSet.attr('data-option-key'),
value = $jthis.attr('data-option-value');
// parse 'false' as false boolean
value = value === 'false' ? false : value;
options[ key ] = value;
if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
// changes in layout modes need extra logic
changeLayoutMode( $jthis, options )
} else {
// otherwise, apply new options
$jcontainer.isotope( options );
}
return false;
});
});
</script>
Any help will be appreciated
Thank you
edit: after seeing the portfolio pages. you can change the query_post command according your needs.
query_posts( 'cat=id' );
where 'id' is the number id of your category.
See http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category for more info.
To only show one category instead of all of them:
Replace this:
$categories = get_categories('taxonomy=portfolio_cat&title_li=');
with this:
$categories[] = get_category('cat=4'); // replace 4 with category ID you're looking for
I found this solution & it worked for me.
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'posts_per_page' => -1,
'portfolio-cats' => 'YOUT PORTFOLIO CATEGORY SLUG',
'orderby' => 'ID',
'order' => 'DESC'
);