在Wordpress中按标签显示帖子

时间:2012-12-01 08:16:59

标签: php wordpress wordpress-plugin

我在Wordpress中有这个插件,我已经对其进行了大量修改。插件的目的最初是显示您告诉它的任何类别的缩略图。截至目前,我已经完成了比这更多的事情。但无论如何,这是插件的短代码..

[categorythumbnaillist 7]

7当然是类别ID。该插件获取任何类别的帖子并使用此代码对其进行排序:

$myposts = get_posts( 'numberposts=-1&&category='.$listCatId[1].'&&orderby=
'.$categoryThumbnailList_OrderType.'&&order='.$categoryThumbnailList_Order );

现在,我希望插件只显示其中包含“新闻”标签的帖子。所以我做了以下事情:

$args=array(
          'tag' => 'news',
          'showposts'=>5,
        );
$myposts = get_posts( $args );

如果其中包含“新闻”标签,则会显示5个帖子。 但问题是 ...

我将在一个页面上多次使用此插件。因此,当我使用上面列出的具有不同类别ID的短代码时,插件不起作用,因为我没有将短代码类别ID与$ myposts代码链接。 :(

我将使用我的新闻类别,照片类别和音频类别的插件。我希望它通过短代码显示每个类别的缩略图(就像插件的目的一样),但也只显示带有“新闻”标签的新闻帖子......仅用于新闻类别。我如何组合我的两个代码使其正常运行并只显示带有“新闻”标签的新闻帖子,同时仍然正确显示其他类别的帖子...所有通过插件应该做的短代码?所以例如......我有......

[categorythumbnaillist 3] (news category)
[categorythumbnaillist 5] (photos category)
[categorythumbnaillist 7] (audio category)

我希望新闻只显示带有“新闻”标签的新闻帖子,照片显示照片类别帖子和音频以显示音频类别帖子。再一次,我已经想出了如何做其中一个,我只是不知道如何使代码同时执行。

真的很感激任何帮助! :)

1 个答案:

答案 0 :(得分:0)

请使用以下代码或插件

<?php
 $postslist = get_posts('numberposts=5&orderby=date&tag=heresthetag');
 foreach ($postslist as $post) :
    setup_postdata($post);
 ?>

 <?php $the_image = get_image(); ?>
    <div class="newspage" <?php if($the_image != "") { ?> style="min-height:5.00em;" <?php } ?>>
<?php if($the_image != "") {?>
        <div class="newspage-img"><a href="<?php the_permalink() ?>"><?php echo $the_image; ?></a>
        </div>
            <div class="newspage-content"><?php }  else {?><div class="newspage-content" style="padding-left:0;"><?php }?>
            <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <div class="entry">
                <?php the_excerpt() ?>
                <p><span class="read_more"><a href="<?php the_permalink(); ?>">Read more...</a></span> <span class="feedback"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span></p>
                </div>
            </div>
    </div>
 <?php endforeach; ?>

插件 - http://wordpress.org/extend/plugins/posts-by-tag/