WordPress 精选帖子并分享此问题

发布于 2024-12-10 00:38:31 字数 1939 浏览 0 评论 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> 

im having some trouble with this featured post function that I made. the issue that im having is that when query('showposts=1'); is set the featured post is not picked up. however when I put query(''); the sharethis plugin doesn't work. can any one please help me on what I might be doing wrong.

<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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2024-12-17 00:38:31

showposts 自版本 2.1 起已被弃用,因此最好使用 posts_per_page 代替。不确定它是否会产生任何影响,但您也可以将 PHP 的前两行替换为 $featured = new WP_Query('showposts=1');

至于是什么导致了我的问题不确定,您的查询对我来说看起来不错,并且您没有提到“共享此失败”的方式。我不熟悉“分享此”插件,但大多数此类插件都会使用附加到 the_content 过滤器的过滤器功能将其内容添加到帖子中。也就是说,可能只是您使用的是 the_excerpt() 而不是 the_content()

showposts is been deprecated since version 2.1, so it might be better to use posts_per_page instead. Not sure if it will make any difference, but you could also replace the first two lines of PHP with $featured = new WP_Query('showposts=1');

As to what is causing the problem I am not sure, your query looks fine to me and you didn't mention in what way Share This failed. I'm not familiar with the Share This plugin, but most such plugins add its content to the post using a filter function attached to the the_content filter. That said, it might just be that you are using the_excerpt() and not the_content().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文