dsgtew3241 2013-12-16 08:40
浏览 29
已采纳

Wordpress帖子的自定义模板

On WordPress, I have created "Categories" under "Posts". So what I' am doing is adding new "Post" under their respective Category. Example of some Category are "Photo Gallery, Press Releases, Video Gallery".

Now, I' am trying to display from category slug "press-releases". So my URL structure will be www.example.com/press-releases/xyz

I have already read the documentations and few other blogs regarding this but can't really seem to understand. I' am abit confused when it come to doing this. Can anyone help me.

  • 写回答

2条回答 默认 最新

  • douwei8295 2013-12-16 08:47
    关注

    There is probably few ways to do this I would say the easy way would be to create a template-page like this:

    PHP CODE

    <?php /* Template Name: Available Lots */?>
    <?php get_header();?>
    
    <?php // The Query
          // Replace here-goes-the-slug with what you are trying to find
          query_posts( array ( 'category_name' => 'here-goes-the-slug', 'posts_per_page' => -1 ) );?>
    
    <?php if(have_posts()):?>
    <?php // The Loop
          while ( have_posts() ) : the_post();?>
    
    // Here goes the code if there is posts found
    
    <?php endwhile; ?>
    <?php else: ?>
    
    // Here goes the code if there is no posts in this category
    
    
    // This code is very important it resets the query for new use
    <?php // Reset Query
          wp_reset_query(); ?>
    
    <?php get_footer();?>
    

    This will create a template page for you, now create a new page in your WP. Call it what ever you like on the right side you will see "Template" drop down menu. From this menu select this template you have just created and you are good to go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真