Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按标签定制页面?_Php_Html_Wordpress - Fatal编程技术网

Php 按标签定制页面?

Php 按标签定制页面?,php,html,wordpress,Php,Html,Wordpress,我想在我的网站上创建一个博客,但是我已经创建了自定义页面,但是当我用标签blog发布文章时,它们也会出现在我的索引中,我只是想让它们出现在我的blog.php页面上。我该怎么做 这是我的模板代码 <pre> <?php /* template name: Blog */ ?> <?php get_header(); ?> <div class="switch"> <div class="switch-left">

我想在我的网站上创建一个博客,但是我已经创建了自定义页面,但是当我用标签blog发布文章时,它们也会出现在我的索引中,我只是想让它们出现在我的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();?>
使用此代码而不是

<?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,你的slug应该像blog或者blog,如果它不正确,它就不会工作。它与WordPress中显示的不完全一样,例如,它将显示类似于Home Blog的内容,但slug是Home Blog。。确保找到正确的slug。

我想做的是,每个带有标签Blog的帖子都只出现在我的博客模板中,而不是我的索引中。这个作品100%是我直接从我的网站复制的。。所以你可能没有正确输入slug名称。好的,你能给我举个例子看看我的代码是什么样子的吗?因为我不知道是否在我的循环中使用标签。谢谢。它可以工作,但仍然在索引中显示它们。phpI不知道你的意思,它在索引中显示它们,但如果你是新手,我会假设你没有single.php。。。您还需要显示单个内容的single.php页面,例如,如果您在文章中单击ReadMore
<?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(); ?>