0

私が作成したこの注目の投稿機能に問題があります。私が抱えている問題は、query('showposts=1'); の場合です。注目の投稿がピックアップされないように設定されています。ただし、 query(''); を入れると sharethis プラグインは機能しません。誰でも私が間違っているかもしれないことについて私を助けてください。

<div id="block_feature">
    <div id="featured_post" class="post">
        <div class="post_inner">

            <?php
            $featured = new WP_Query();
            $featured->query('showposts=1');
            while($featured->have_posts()) : $featured->the_post();

            //$wp_query->in_the_loop = true; // This line is added so that the_tags('') will work outside the regular loop.
            $featured_ID = $post->ID; // We'll store this here so that we know to skip this post in the main loop
            ?>

                <?php if(get_post_meta($post -> ID, 'feature', true)) { ?>


                    <?php if (get_post_meta($post->ID, 'large_preview', true)) { ?>
                        <div class="post_image">
                        <img src="<?php echo get_post_meta($post->ID,'large_preview',true);?>" width=150px; height=150px alt="Featured Post"/>
                        </div>
                    <?php } ?>

                        <div class="excerpt">
                        <h2><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                        <small>on <?php the_time('M d'); ?> in <?php the_category(',');?> tagged <?php the_tags(''); ?></small>
                        <?php the_excerpt();?>
                        </div>
                        <a href="<?php the_permalink(); ?>" class="readMore">Read More</a>  


                <?php } ?>
            <?php endwhile; ?> 
        </div>                        
    </div>                   
</div> 
4

1 に答える 1

1

showpostsはバージョン 2.1 から非推奨になっているため、posts_per_page代わりに使用することをお勧めします。違いがあるかどうかはわかりませんが、PHP の最初の 2 行を次のように置き換えることもできます。$featured = new WP_Query('showposts=1');

問題の原因についてはわかりませんが、クエリは問題ないように見えますが、Share Thisが失敗した方法については言及していません。Share This プラグインには詳しくありませんが、そのようなプラグインのほとんどは、フィルターに添付されたフィルター機能を使用してコンテンツを投稿に追加しthe_contentます。とは言っても、 を使用していて、 を使用していないだけかもしれませthe_excerpt()the_content()

于 2011-10-14T11:58:42.820 に答える