添加“get_template_part”后,内容会被替换

时间:2013-09-11 11:02:43

标签: wordpress templates themes wordpress-theming

我正在尝试使用来自themeforest的模板在我的主页上添加一个Slider,但我没有得到任何支持。

我将以下代码添加到标题中:

<?php get_template_part ( 'includes/featured/featured-call'); ?>

并且这段代码调用了feature-call.php,并从那里调用了另一个文件,flexislider.php看起来像这样:

<section>
<div class="spaced-wrap clearfix">
    <div class="flexslider-container clearfix">
        <div class="flexslider-loader">
            <div class="flexslider">
            <ul class="slides">
                <?php
                $captioncodes="";
                $count=0;
                query_posts( array( 'post_type' => 'mtheme_featured', 'showposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC') );
                ?>
                <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>

                <?php
                $image_id = get_post_thumbnail_id(($post->ID), 'full'); 
                $image_url = wp_get_attachment_image_src($image_id,'full');  
                $image_url = $image_url[0];

                $custom = get_post_custom(get_the_ID());
                $featured_description="";
                $featured_link="";

                if ( isset($custom["featured_bigtitle"][0]) ) $featured_bigtitle=$custom["featured_bigtitle"][0];

                if ( isset($custom["featured_description"][0]) ) { $featured_description=$custom["featured_description"][0]; }
                if ( isset($custom["featured_link"][0]) && $custom["featured_link"][0]<>"" ) { 
                    $featured_link=$custom["featured_link"][0];
                    } else {
                    $featured_link = get_post_permalink();
                }

                //$textblock=$featured_description;
                $title=get_the_title(); 
                $text=$featured_description;
                $permalink = $featured_link;
                $count++;
                ?>
                <li>
                <a href="<?php echo $permalink; ?>">
                    <img src="<?php echo $image_url; ?>" alt="<?php the_title(); ?>" />
                </a>
                <?php

                $titlecode ='<div class="flex-title"><a href="'.$permalink. '">' .$title . '</a></div>';
                $captioncodes ='<div class="flex-caption">' . $text . '</div>';
                $bigtitle='<div class="flex-bigtitle"><a href="'.$permalink. '">'.$featured_bigtitle.'</a></div>';

                echo '<div class="flex-caption-wrap">';
                echo $titlecode;
                echo $captioncodes;
                echo $bigtitle;
                echo '</div>';

                ?>
                </li>
                <?php                   
                endwhile; endif; 
                ?>
            </ul>
          </div>
      </div>
    </div>
</div>

我遇到的问题是,一旦这样做,它会将滑块作为帖子加载到主页而不是我选择的页面(主页)。如果我从header.php删除“get_template_part”,页面加载正常,否则滑块作为帖子出现,我看不到我在wordpress上阅读时选择的页面。

我的网站是http://van-london.com/

1 个答案:

答案 0 :(得分:0)

我做到了!

我需要的只是“get_template_part”之后的代码

<?php wp_reset_query(); ?>

完成! :)