2015-10-20 82 views
2

在网站上工作,我需要有一个单独的模板/页面才能显示该帖子。在其他模板/页面上显示一个帖子

在主页上(索引)Ill循环遍历我的类别并仅显示其中的一部分 - 事件 - 新闻 - 引用。

像这样:

  <?php 
      $query = new WP_Query(array('category_name' => 'Events')); 

      if ($query->have_posts()) 
      { 
       while ($query->have_posts()) : $query->the_post(); 
         $haveEvents = true; 
         if ($eventCount < 3) { 
          $eventCount++; 
          ?> 
          <div class="event-tile"> 
           <div class="event-tile-content"> 
            <h3><?php the_title(); ?></h3> 
            <h4><?php the_time('F jS, Y'); ?></h4> 
            <a href="<?php the_permalink(); ?>" class="event-tile-read-more">Lees meer</a> 
           </div> 
          </div> 
          <?php 
        } 
       endwhile; 
      } 

,每个节都有一个阅读所有和读取特定项目按钮: enter image description here enter image description here

我已经找到了如何显示一个类别中的所有职位分离页面上命名为:page-posts.php

On page-posts.php我只是检查我是哪个页面,并根据哪个页面进行查询以显示帖子内的内容指定类别现在我不能,如何显示在主页上(的index.php)单后,单后的网页上(甚至不花钱像谷歌时段后)计算出

 $query; 
     if (is_page('events')) { 
      $query = new WP_Query(array('category_name' => 'Events')); 
     } 
     elseif (is_page('news')) { 
      $query = new WP_Query(array('category_name' => 'News')); 
     } 

     if ($query->have_posts()) 
     { 
etc.. 

。 ..

在我使用的操作按钮:

<a href="<?php the_permalink(); ?>" class="event-tile-read-more">Lees meer</a> 

这让我回到主屏幕。 (刚开始使用Wordpress)

回答

1

在Wordpress主题single.php用于显示帖子。如果它不存在,下降到使用index.php

请尝试移动page-posts.phpsingle.php

+0

啊谢谢,这个作品,只是为了记录,我已经像几个小时左右Google搜索,所以非常感谢! –

+0

顺便说一句,我现在使用两个,单一的只是一个类别中的所有职位的特定职位和网页发布! –

0

也许最好使用archive-events.php。您可以创建自定义帖子的存档。

可以这样做:其中活动是您的自定义发布类型。然后登陆事件存档页面。

据我可以看到你的问题是,该职位是全球职位(从你家)。所以也许你可以setup_postdata($ post),或者使用home_url('url')函数。

+0

嘿沃特,感谢响应。我已经找到了使用存档的东西,但这对我没有帮助。有什么优势,因为single.php适用于一个职位 –

相关问题