【问题标题】:Display Portfolio Posts only from certain category with PHP仅使用 PHP 显示特定类别的投资组合帖子
【发布时间】:2022-02-18 18:01:15
【问题描述】:

美好的一天。

我正在使用一个包含 Portfolio 的主题。投资组合当前显示列出的所有类别。如何将其更改为仅显示某些类别,即。设计和图像?

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

<?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>

任何帮助将不胜感激

谢谢

【问题讨论】:

  • 我们需要修复这个问题的信息可能在portfolio-2col.php3col.php4col.php
  • 只要一个人就能让我们开始......

标签: php wordpress


【解决方案1】:

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

query_posts( 'cat=id' );

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

请参阅http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category 了解更多信息。

【讨论】:

    【解决方案2】:

    只显示一个类别而不是所有类别:

    替换这个:

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

    用这个:

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

    【讨论】:

    • 感谢您的回答。我按照你说的替换了它,但没有任何变化,只是现在它显示了所有类别的图像,并且不再让我在顶部选择在不同类别之间切换。
    • 嗯,你的最终目标是什么?你想做什么?
    • G 查看以下站点:http-solutions.com/themes/quiven/?page_id=1240。您将看到列出的类别。目前它显示了所有可用的猫。我只希望它显示猫的“徽标”。我该怎么做?
    • 你能登录wordpress吗?查看您的投资组合标签。
    • 你看,基本上我想做的是有 2 个 Wordpress 页面,每个页面显示 4-col 组合,每个只显示某些类别。目前每个带有作品集模板的页面都会显示所有可用的类别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多