首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress文章的自定义模板

Wordpress文章的自定义模板
EN

Stack Overflow用户
提问于 2013-12-16 08:40:24
回答 2查看 69关注 0票数 2

在WordPress上,我在"Posts“下创建了”类别“。所以我要做的是在他们各自的分类下增加新的“帖子”。一些类别的例子是“图片库,新闻稿,视频画廊”。

现在,我正在尝试从类别中显示“新闻稿”。所以我的URL结构是www.example.com/press-releases/xyz

我已经阅读了有关这方面的文档和其他博客,但似乎并不能真正理解。说到做这件事,我有点困惑。有人能帮我吗。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-16 08:47:30

也许没有什么方法可以做到这一点--我想说的是,简单的方法是创建这样的模板页面:

PHP代码

代码语言:javascript
复制
<?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();?>

这将为您创建一个模板页面,现在在您的WP中创建一个新页面。把它称为任何你喜欢在右边你会看到“模板”下拉菜单。从这个菜单中选择您刚刚创建的模板,您就可以继续了。

票数 2
EN

Stack Overflow用户

发布于 2013-12-16 09:23:14

试试下面的代码:

只要将"CATEGORYNAME“替换为您想要的类别名称:

代码语言:javascript
复制
<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
  // do whatever you want
?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>

谢谢

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20606518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档