English 中文(简体)
语言压力——按习俗员额类型和类别分列的员额,每个类别自动列入DIV
原标题:WordPress - Getting Posts by Custom Post Type and Category, with each category automatically encased in a DIV

Sorry for the long question title. I was attempting to be accurate.

我需要设计一个言语调问,将自动从某种习俗员额类别中抽出员额,查明每个员额的分类方式,然后按职类将员额排到一页,每个类别都列入自己的DIV。

例如,我有一个称为“Map数据”的习俗员额类型。 在这种习俗员额类型中,我有一个称为“工业”的超等级分类经济,在这个分类中,一些类别,即“Category #1”、“Category #2”,等等。 每个职类都有若干员额。

因此,询问应列出海关员额类别中的所有类别,然后得出这样的结果:

<div id="category-1">
     <div class="post">This is a post in Category 1</div>
     <div class="post">This is another post in Category 1</div>
</div>
<div id="category-2">
     <div class="post">This is a post in Category 1</div>
     <div class="post">This is another post in Category 1</div>
</div>

然而,我有以下与缺省性语言类系统合作的法律,要么需要重新制定,要么需要更新,以便它能够处理习惯员额类型及其税务问题。

<?php 
    $cat_args=array();
    $categories=get_categories($cat_args);
    foreach($categories as $category) {
        $args=array(
             category__in  => array($category->term_id),
        );
    $posts=get_posts($args);
        if ($posts) {
            echo  <div class="cat" id="  . $category->slug. " name="  . $category->name. "> ;
            foreach($posts as $post) {
          setup_postdata($post); 
?>

<?php the_title();?>
<?php the_content();?>

<?php
        } // foreach($posts
        echo  </div> ;
      } // if ($posts
    } // foreach($categories
?>

如果任何人能够向我提供最新的法典,以尝试,或提供一个工作榜样,那将受到非常赞赏。

最佳回答

i) 这样做是为了所有税种,但可以很容易地修改,以积极从事你试图做的工作。

// for a given post type, return all
$post_type =  shows ;
$tax =  show-topic ;
$tax_terms = get_terms($tax, array( orderby  =>  id ,  order  =>  ASC ,  exclude  =>  135, 49, 25, 24, 54 ));
if ($tax_terms) {
    foreach ($tax_terms as $tax_term) {
        $args = array(
             post_type  => $post_type,
            "$tax" => $tax_term->slug,
             post_status  =>  publish ,
             posts_per_page  => - 1,
             orderby  =>  title ,
             order  =>  ASC ,
             caller_get_posts  => 1
            ); // END $args
        $my_query = null;
        $my_query = new WP_Query($args);
        if ($my_query->have_posts()) {
            echo  <h3>  . $tax_term->name .  </h3> ;
            while ($my_query->have_posts()) : $my_query->the_post();
            ?>
          <div class="post row" id="post-<?php the_ID(); ?>">
                    <div class="thumb-box three column">
                        <?php
            $src = wp_get_attachment_image_src(get_post_thumbnail_id());
            if (has_post_thumbnail()) {
                the_post_thumbnail();
            } else {
                if (get_post_meta($post->ID, "thumbnail", true)):
                    ?>
                                <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
                            <?php else: ?>
                                <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php bloginfo( stylesheet_directory ); ?>/images/insp-tv-small.png" alt="<?php the_title(); ?>" /></a>
                            <?php endif;
            }
            ?>
                    </div>
                    <div class="post-content nine columns">
                        <h4 class="posttitle archiveposttitle">
                            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( Permanent Link to ,  buddypress ) ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                        </h4>
                        <div class="entry">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                </div>
          <?php
            endwhile;
        } // END if have_posts loop
        wp_reset_query();
    } // END foreach $tax_terms
} // END if $tax_terms

?>
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签