显示组合仅使用PHP从某些类别发布帖子

时间:2013-02-22 07:26:43

标签: php wordpress

美好的一天。

我正在使用具有投资组合的主题。该投资组合目前显示列出的所有类别如何更改它以仅显示某些类别,即。设计和图像?

以下是投资组合模板页面的代码

<?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内容:

<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><a href="#filter" data-option-value=".<?php echo $category->slug;?>" title="Filter by <?php echo $category->name;?>"><?php echo $category->name;?></a></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].'&amp;w=218&amp;h=200&amp;zc=1&amp;q=100&amp;s=1" alt="'.get_the_title().'" />';?>
</figure>
<?php } ?>

<div class="mask">
        <header class="box-headline">
            <?php echo '<h4><a href="'.get_permalink().'">'; echo ''.get_the_title().''; echo '</a></h4>'; ?>
        </header>
    <div class="content">
        <p><?php echo $gogo_portfolio_short_desc; ?></p>
        <a href="<?php echo get_permalink(); ?>" class="info"><span>Read More &raquo;</span></a>
    </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>

任何帮助将不胜感激

谢谢

2 个答案:

答案 0 :(得分:0)

编辑:看到投资组合页面后。您可以根据需要更改query_post命令。

query_posts( 'cat=id' );

其中'id'是您的类别的编号ID。

有关详细信息,请参阅http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category

答案 1 :(得分:0)

仅显示一个类别而不是全部类别:

替换它:

$categories =  get_categories('taxonomy=portfolio_cat&title_li=');

用这个:

$categories[] = get_category('cat=4'); // replace 4 with category ID you're looking for