2014-01-14 110 views
1

我要创建我的网站里面的博客,但我已经创建自定义的页面,但是当我做与标签“博客”的帖子也出现在我的索引我只是我希望他们我的页面调用blog.php的上。我怎样才能做到这一点?按标签自定义页面?

这是我的模板代码

<pre> 
<?php 
/* 
template name: Blog 
*/ 
?> 
<?php get_header(); ?> 
<div class="switch"> 
<div class="switch-left"> 
    <span style="text-shadow:0 1px 23px #ff0000;color: #000;">Blog de Noticias</span> 
</div> 
< /div> 
<div class="main section" id="main"> 
<div class="widget Blog" id="Blog1"> 
    <div class="blog-posts hfeed"> 
     <?php query_posts('tag=Blog'); if (have_posts()) : while (have_posts()) : the_post(); ?> 
     <div class="post bar hentry"> 
      <h3 class="post-title entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
      <div class="post-header-line-1"></div> 
      <div class="post-body entry-content"> 
       <div class="box-peli"> 
        <span style="float:left; padding:0px 10px 5px 0px;"> 
         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
         <?php if (has_post_thumbnail()) { 
          $foto = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); 
          $src = $foto['0']; 
          echo '<img src="'.$src.'" class="alignnone" alt="'.get_the_title().'" width="114" height="170">'; 
         }else{ ?> 
          <img src="<?php bloginfo('template_url');?>/images/no-image.jpg" class="alignnone" alt="<?php the_title();?>" width="114" height="170"/> 
         <?php }?>       
         </a> 
        </span> 
       </div> 
      </div> 
     <div style="clear: both;"></div> 
     </div> 
     <?php endwhile; endif; ?> 
    </div> 
    <div class="blog-pager" id="blog-pager"> 
     <?php if(function_exists('pagenavi')) { pagenavi(); } ?> 
    </div> 
    <div class="clear"></div> 
    <?php if(!is_paged()) { ?> 
    <div id="slide-wrapper"> 
     <div class="slide section" id="slide"> 
      <div class="widget HTML" id="HTML4"> 
       <div id="maskolis"> 
        <?php get_template_part('postsByTag');?> 
       </div> 
      </div> 
     </div> 
    </div> 
    <?php } ?> 
</div> 
</div> 
<?php get_footer();?> 

回答

0
<?php 
    query_posts(array ('category_name' => 'category-slug-name-goes-here', 'posts_per_page' => -1)); 
?> 

使用此代码,而不是

<?php query_posts('tag=Blog'); 

很接近,但也不能令人信服,让我知道它是如何摸索出适合你。

从代码:

<?php query_posts('tag=Blog'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

让它这样:

<?php query_posts(array ('category_name' => 'category-slug-name-goes-here', 'posts_per_page' => -1)); 
if (have_posts()) : while (have_posts()) : the_post(); ?> 

看看你的WordPress里面,你的鼻涕虫应该像“博客”或者“博客”的不正确也不会工作。作为显示例如WordPress的,它会显示这样的东西“家庭博客”,但蛞蝓是“家庭博客” ..确保你找到正确的蛞蝓这是不完全的。

+0

我正在试图做的是,每一个岗位,添加标签“博客”刚刚出现在我的博客的模板,而不是在我的索引 – user3195506

+0

这个工程100%,我直接复制它自己的网站的。所以你可能不正确输入“slug-name”。 – Ljubisa

+0

好的,你能告诉我一个例子,我的代码是怎么看?因为idont知道我的循环内是否使用标签。 – user3195506

相关问题