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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示