1

我创建了一个自定义帖子类型的框,其中包含连续四行的徽标和文本。我为此创建了一个工作帖子存档,但现在我需要将它们带到另一个页面中,该页面在需要显示自定义帖子类型之前和之后有额外的文本和图像。这样做的正确方法是什么?

我的基本页面模板:

<?php
/*
Template Name: Work
*/

get_header(); ?>

<div id="body">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>

    <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
    <?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>

这是我试图在页面模板中显示的存档 php:

<?php 
 get_header();
?>

<div class="post">

    <?php if (have_posts()) : ?>

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

        <?php /* If this is a category archive */ if (is_category()) {

            ?>


    <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>

        <?php } ?>

<div id="body"><h2>Case Studies</h2></div>

        <?php while (have_posts()) : the_post(); ?>

                <div<?php post_class('margin') ?> id="post-<?php the_ID(); ?>">


<div class="casestudy"><a href="<?php the_permalink() ?>" class="anchor-hover">

    <?php echo get_the_post_thumbnail( $post->ID, '180,180' ); ?>
    <span class="details">
    <div class="anchor-hover details-h3"><?php the_title(); ?></div>

<p class="desc"><?php echo get_post($post_id)->post_excerpt; ?></p>

</span> 
</a>
    </div>


<?php endwhile; endif; ?>
<div class="clear"></div>

        </div>

</div>

<?php get_footer(); ?>
4

1 回答 1

-1

这是你要找的吗?

<?php 

$args = array( 'post_type' => 'YOUR CUSTOM POST TYPE', 'posts_per_page' => THE NUMBER OF POSTS YOU WANT TO DISPLAY );     

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<div<?php post_class('margin') ?> id="post-<?php the_ID(); ?>">

<div class="casestudy"><a href="<?php the_permalink() ?>" class="anchor-hover">

<?php echo get_the_post_thumbnail( $post->ID, '180,180' ); ?>
<span class="details">
<div class="anchor-hover details-h3"><?php the_title(); ?></div>

<p class="desc"><?php the_excerpt(); ?></p>

</span> 
</a>
</div>

<?php endwhile;
endif;

// Reset Post Data
wp_reset_postdata();

?>
于 2013-11-15T02:17:37.963 回答