【问题标题】:only show blog-entries of specific categories on my page (wordpress)仅在我的页面上显示特定类别的博客条目(wordpress)
【发布时间】:2013-09-17 13:35:27
【问题描述】:

排除“未分类”我有三个类别:“新闻”、“E1”、“E2” 我也有两个页面(E1,E2)具有相同的博客模板。计划是在每个页面上显示“新闻”的所有条目和所有合适的“E *”类别。我该怎么做? 我使用的主题来自 Theme-Horse 的 ist Attitude-Free。

<?php
/**
 * Template Name: Blog Full Content Display
 *
 * Displays the Blog with Full Content Display.
 *
 * @package Theme Horse
 * @subpackage Attitude
 * @since Attitude 1.0
 */
?>

<?php get_header(); ?>



<?php $args = array(
         'posts_per_page'   => 5,
         'offset'           => 0,
         'category'         => 'E1',
         'orderby'          => 'post_date',
         'order'            => 'DESC',
         'include'          => '',
         'exclude'          => '',
         'meta_key'         => '',
         'meta_value'       => '',
         'post_type'        => 'post',
         'post_mime_type'   => '',
         'post_parent'      => '',
         'post_status'      => 'publish',
         'suppress_filters' => true ); 

 $posts_array = get_posts( $args ); ?>



<?php
/** 
 * attitude_before_main_container hook
     */
    do_action( 'attitude_before_main_container' );
?>
<?php
/**
 * Überschrift
 *
 * bla
 */
?>
<h3>Content:</h3>

<div id="container">
<?php
    /** 
     * attitude_main_container hook
     *
     * HOOKED_FUNCTION_NAME PRIORITY
     *
     * attitude_content 10
         */
        do_action( 'attitude_main_container' );
    ?>
</div><!-- #container -->

<?php
    /** 
     * attitude_after_main_container hook
     */
    do_action( 'attitude_after_main_container' );
?>

<?php get_footer(); ?>

【问题讨论】:

  • 您的问题与原来的问题有很大不同,但是,这就是您页面中的全部内容吗?
  • 遗憾的是,我怀疑它是因为我使用的主题。每个 *.php 中几乎没有代码

标签: php wordpress blogs


【解决方案1】:

如果要检索某个类别的所有帖子,可以使用 get_posts() wordpress 函数。

例如

<?php $args = array(
         'posts_per_page'   => 5,
         'offset'           => 0,
         'category'         => 'E1',
         'orderby'          => 'post_date',
         'order'            => 'DESC',
         'include'          => '',
         'exclude'          => '',
         'meta_key'         => '',
         'meta_value'       => '',
         'post_type'        => 'post',
         'post_mime_type'   => '',
         'post_parent'      => '',
         'post_status'      => 'publish',
         'suppress_filters' => true ); 

 $posts_array = get_posts( $args ); ?>

然后你只需要循环进入这个数组,并根据需要显示它们。

如果您想了解更多信息,请联系page

【讨论】:

  • 我将此代码集成到“get_header()”函数下,但没有任何反应。模板上方现在的样子。
  • 试试 '; print_r($posts_array);回声''; ?>
  • 在sn-p之前还是之后?
  • sn-p 之后。这些代码只会显示数组中的信息。你必须循环它。
  • 现在发生了一些事情,但不像预期的那样svs03.azurewebsites.net/?page_id=331
猜你喜欢
  • 1970-01-01
  • 2016-11-15
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
相关资源
最近更新 更多