0

WordPress で特定の投稿に属する画像を別のページに表示するのに問題があります。私が探しているのは、特定のカテゴリ内のすべての投稿を一覧表示し、タイトル、抜粋、および「例を表示」リンクを表示するホームページです。例を表示するリンクは、投稿に属するすべての画像をライトボックスに表示しますが、ホームページには表示されます。

これまでのところ私はこれを持っていますが、今はちょっと行き詰まっています。

<?php query_posts('cat=15&order=DSC'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="col-md-6">
            <div class="pakket-block">
                <h3><?php the_title(); ?></h3>
                <?php the_excerpt(); ?>
                <span class="read_more"><a href="<?php the_permalink(); ?>" rel="shadowbox">View examples</a></span>    
            </div> <!-- /.pakket-block -->
        </div> <!-- /.col-md-6 -->
    <?php endwhile; endif; ?>
<?php wp_reset_postdata(); // reset the query ?>
4

2 に答える 2

0

これはかなり大まかな例です(現在の環境ではこれをテストできませんでした)

これにより、ページに添付されているすべての画像を取得するための正しい方向に進むはずです。

この関数を functions.php に入れます。

    function get_match( $regex, $content ) {
        preg_match($regex, $content, $matches);
        return $matches[1];
    } 

そして、これはテンプレートファイルにあります:

    query_posts('cat=15&order=DSC');
    if ( have_posts() ) : while ( have_posts() ) : the_post();


        // Extract the shortcode arguments from the $page or $post
        $shortcode_args = shortcode_parse_atts(get_match('/\[gallery\s(.*)\]/isU', $post->post_content));

        $ids = $shortcode_args["ids"];

        // get the attachments specified in the "ids" shortcode argument
        $attachments = get_posts(
            array(
                'post_parent' => $post->ID,
                'post_status' => 'inherit', 
                'post_type' => 'attachment', 
                'post_mime_type' => 'image', 
                'order' => 'menu_order ID', 
                'orderby' => 'post__in',
            )
        );


        print_r($attachments);


    endwhile; endif; 
    wp_reset_postdata();
于 2013-09-17T08:19:08.507 に答える