简体   繁体   中英

How to display custom post type by custom taxonomy?

My homepage is displaing my listings( my custom post type) by the order i enter them. I would like my listings that have the custom taxonomy "tag" (Special offer) to be displayed on my first page from my homepage and after that the rest of the listings exactly how they where before. I am new in to wordpress and hope i asked my question right

This is my homepage code

<div id="content">
<?php include (TEMPLATEPATH . '/lib/slider.php'); ?>    

<?php
$args = array(
'post_type' => 'listings',
'paged' => $paged,
'showposts' => 8 ,
'oferta' =>"oferta"
);
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query($args);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>   
<div class="post propbox <?php if (++$counter % 2 == 0) { echo "lastbox"; }?> clearfix" id="post-<?php the_ID(); ?>">
<div class="archimg">

<?php  if( has_term( 'featured', 'type', $post->ID ) ) { ?>
<span class="featspan">Featured</span>
<?php } else if ( has_term( 'sold', 'type', $post->ID ) ){ ?>
<span class="soldspan">Sold</span>
<?php } else if ( has_term( 'reduced', 'type', $post->ID ) ){ ?>
<span class="redspan">Reduced</span>
<?php } ?>

<?php
    if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink() ?>"><img class="propimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&amp;h=180&amp;w=310&amp;zc=1" alt=""/></a>
        <?php } else { ?>
    <a href="<?php the_permalink() ?>"><img class="propimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.jpg" alt="" /></a>
<?php } ?>
</div>
<div class="cover">
    <div class="title">
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    </div>
    <div class="propmeta">
    <div class="proplist"><span>Price</span> <span class="propval"> <?php $price=get_post_meta($post->ID, 'wtf_price', true); echo $price; ?></span></div>
    <div class="proplist"><span>Location</span> <span class="propval"> <?php echo get_the_term_list( $post->ID, 'location', '', ' ', '' ); ?></span></div>
    <div class="proplist"><span>Property type</span> <span class="propval"><?php echo get_the_term_list( $post->ID, 'property', '', ' ', '' ); ?></span></div>
    <div class="proplist"><span>Area</span> <span class="propval"> <?php echo get_the_term_list( $post->ID, 'area', '', ' ', '' ); ?></span></div>
    </div>
    <div class="entry">
        <?php wpe_excerpt('wpe_excerptlength_archive', ''); ?>
        <a class="morer" href="<?php the_permalink() ?>">Check this</a>
        <div class="clear"></div>
    </div>
</div>
</div>

<?php endwhile; ?>

<div class="clear"></div>

<?php getpagenavi(); ?>

<?php $wp_query = null; $wp_query = $temp;?>

</div>

This is my main content content sorry how can i rearenge this so it fits my needs

you can use tax_query like by here

$args = get_posts( array(
    'post_type' => 'my_post_type',
    'tax_query' => array(
        array(
            'taxonomy' => 'my_taxonomy',
            'field' => 'slug',
            'terms' => 'webdesign'
        )
    )
) );

$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query($args);

You have to pass the arguments array to you $wp_query->query($args); in which you define the tag name or category name , taxonomy of tag or taxonomy of category

$args = array(
'post_type' => 'your custom post type name',
'paged' => $paged,
'showposts' => 8 ,
'your custom goes here taxonomy' =>"tag name or category name"
);
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query($args);

Generally taxonomy name is what you defined in register_taxonomy('here_goes_taxonomy',array('post_type'), array(...))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM