如何显示当前点击的帖子

时间:2014-04-11 13:59:36

标签: php jquery html5 wordpress

您好我有投资组合列表,我想显示当前点击的投资组合项目的内容。这是我的代码。当我点击其中一个项目时,它会显示所有项目的内容。

<div class="row">
     <?php
        // The Query
        $the_query = new WP_Query( array( 'post_type' => 'portfolio', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page'=>-1 ) );
        $i = 0;
        // The Loop
        while ( $the_query->have_posts() ) : $the_query->the_post();                                        
            $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
     ?>  
    <div class="col-4">
        <div class="portf" data-toggle="show" data-target="#show">
            <div class="work" data-work="<?php echo $i; ?>">
                <img src="<?php echo $thumbnail[0]; ?>" alt="" title=""> 
            </div>
        </div>
    </div>
<?php $i++; endwhile; ?>
</div>

<div class="show" id="show">
    <div class="show-dialog">
        <div class="show-content">
            <?php
            // The Query
            $the_query = new WP_Query( array( 'post_type' => 'portfolio', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page'=>-1 ) );

            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post();                                        
                $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
            ?>  
            <div class="header">
                <h4 class="title"><?php the_title(); ?></h4>
            </div>
            <div class="show-body">
                <p>
                    <?php the_content(); ?>                        
                </p>
            </div>
            <?php endwhile; ?>          
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

试试这段代码:

<div class="row">
     <?php
        // The Query
        $the_query = new WP_Query( array( 'post_type' => 'portfolio', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page'=>-1 ) );
        $i = 0;
        // The Loop
        while ( $the_query->have_posts() ) : $the_query->the_post();                                        
            $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
     ?>  
    <div class="col-4">
        <div class="portf" data-toggle="show" data-target="#show<?php echo $i; ?>">
            <div class="work" data-work="<?php echo $i; ?>">
                <img src="<?php echo $thumbnail[0]; ?>" alt="" title=""> 
            </div>
        </div>
    </div>
    <?php $i++; endwhile; ?>
</div>

<?php
// The Query
$the_query = new WP_Query( array( 'post_type' => 'portfolio', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page'=>-1 ) );
$i = 0;
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();                                        
    $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
?>  
<div class="show" id="show<?php echo $i; ?>">
    <div class="show-dialog">
        <div class="show-content">
            <div class="header">
                <h4 class="title"><?php the_title(); ?></h4>
            </div>
            <div class="show-body">
                <p>
                    <?php the_content(); ?>                        
                </p>
            </div>          
        </div>
    </div>
</div>
<?php $i++; endwhile; ?>  

这是创造一个单独的节目&#39;每个投资组合项目的div,增加id(例如#show1,#show2等)

然后我更改了您的数据目标,以便它可以包含这些ID并增加:

<div class="portf" data-toggle="show" data-target="#show<?php echo $i; ?>">