修改Wordpress插件以按类别而不是ID#显示帖子

时间:2014-03-05 20:29:47

标签: php jquery wordpress

我正在使用这个Wordpress插件:http://wordpress.org/plugins/carousel-of-post-images/ 它显示了一个帖子&显示特色图像。 它目前设置为按id显示帖子,需要单独输入短代码。是否可以按类别显示帖子,以便我可以设置帖子的类别并仅在滑块中查看该类别?

以下是我认为负责的所有代码。

function copi_carousel_get_images($size = 'medium' , $orderby, $posts, $count, $class = ''){
global $post;

$att_array = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'orderby' => $orderby, 
    'numberposts' => $count,
    );

$postlist = explode(",",$posts);
$sizes = explode(",", $size);
$html = '';
if (count($sizes) == 2)
{
    $width = $sizes[0];
    $height = $sizes[1];
    $size=$sizes;
}
else
{
    $width = get_option($size.'_size_w');
    $height = get_option($size.'_size_h');
}

foreach($postlist as $postid)
{
    if ($postid != '')
        $att_array['post_parent'] = $postid;

    $attachments = get_posts($att_array);

    if (is_array($attachments)){
        foreach($attachments as $att){
            $image_src_array = wp_get_attachment_image_src($att->ID, $size);
            $url = $image_src_array[0];
            if ($url != "")
            {

                $prefix = '<li><a href="'.get_permalink($att->post_parent).'">';
                $suffix = "</a></li>";

                $caption = $att->post_excerpt;

                if(function_exists('thumbGen'))
                    $url = thumbGen($url, $width, $height, 'return=1');

                $image_html = '<img src="%s" height="'.$height.'" alt="%s">';

                $html .= $prefix.sprintf($image_html,$url,$caption,$class).$suffix;
            }
        }
    }
}
return  $html;

}

function show_wp_copi_carousel($atts){
    $skin = 'tango';
    $div='post-carousel';
    $imagesize = 'medium';
    $orderby = 'rand';
    $postid = '';
    $count='10';

if (isset($atts['skin'])) 
    $skin = $atts['skin'];

if (isset($atts['imagesize'])) 
    $imagesize = $atts['imagesize'];

if (isset($atts['orderby'])) 
    $orderby = $atts['orderby'];

if (isset($atts['postid'])) 
    $postid = $atts['postid'];

if (isset($atts['count'])) 
{
    $count = $atts['count'];

1 个答案:

答案 0 :(得分:0)

我使用Coda滑块执行此操作。

首先在头部包含脚本:

<script src="js/jquery.coda-slider-3.0.js"></script>

<script>
$(function(){

  /* Here is the slider using default settings */
  $('#slider-id').codaSlider({
        autoSlide:true,
        autoHeight:false
});

});

</script> 

然后我使用了循环:

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>

<div class="coda-slider"  id="slider-id">
<?php
$args = array('category' => 15, 'numberposts' => 4, 'order'=> 'ASC');
$postslist = get_posts( $args );
foreach ($postslist as $post) :  setup_postdata($post); ?>
<img src="<?php echo $image[0]; ?>"/>
<?php endforeach; ?>
</div>

这应该有效!

注意:要显示帖子信息,只需在循环中包含“the_post”或您要显示的任何内容,滑块脚本将负责轮换。

此外,这需要在模板中使用。