首页 文章

Wordpress - 帖子和页面

提问于
浏览
0

我目前正在开发一个mutlisite wordpress设置,每个站点是一种不同的语言(EG:site.com,site.dk等) .

这些网站包含许多包含静态内容的页面,但我还希望将帖子(博客)包含在这两个网站中 .

Q1 . 是否可以创建一个页面,显示按最新发布日期列出的所有帖子,其下拉列表按类别过滤?我该怎么做呢?我需要参考loop.php吗?

基本上它应该为所有帖子文章返回以下代码...

<article class="post">
<a href="<URL Link to Post Article>" rel="bookmark">
<figure>
<img title="<Post Title>" alt="<Post Title>" src="<http://url/PostImage.jpg>" width="900" height="600" />
</figure>               
<div class="cover">
<h2>Post Title</h2>
<time pubdate="2013-03-27T21:09:59+00:00">November 18, 2012</time>
</div>
</a>
</article>

为什么这不起作用?它没有返回任何东西?

<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article class="post">
<?php get_posts(); ?>
<div id="grid-switcher">
<a href="#" data-block="featured-posts" id="featured">featured</a>
<a href="#" data-block="latest-posts" id="latest" class="active">latest</a>
</div>
<div id="view-blocks">
<div id="latest-post" class="post-grid active">
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(250,250)); // Declare pixel size you need inside the array ?>
<?php endif; ?>
<!-- /post thumbnail -->
<div class="cover">
<h2><?php the_title(); ?></h2>
<time pubdate="<?php the_date(); ?>"><?php the_date('Y-m-d', '<h2>', '</h2>'); ?></time>
</div>
</a>

我已经为上面的内容创建了一个页面模板portfolio-page.php,但是无法找到如何遍历帖子并使用上面的代码返回它们?

Q2 . 如何返回包含所有类别的下拉列表?

Q3 . 如何从下拉列表中按类别筛选?

谢谢你的帮助! :)

对不起,我是PHP和wordpress的新手......

2 回答

  • 0

    这个问题有点模糊,所以我只想分享一些起点:

    A1)要获得帖子列表,您可以使用wordpress中的get_posts功能 . 它已经通过发布日期desc对它们进行排序,如果选择了该类别,您还可以为该类别添加参数 .

    A2)要获得类别的下拉列表,有一个函数可以完全实现:wp_dropdown_categories

    检查文档,因为有很多参数可以与get_posts函数一起使用,所以你应该可以根据需要过滤它们 .

  • 0

    我认为你最好检查一下你运行wordpress的数据库 .

    如果检查wp_posts表,则可以看到可以过滤的差异字段 .

    您最好使用自定义查询来过滤帖子并对其进行排序

相关问题