【发布时间】:2012-06-01 00:15:05
【问题描述】:
我的问题是我无法让 Wordpress 显示我需要的帖子。
我已经尝试使用两种方法,第一种方法是在阅读设置中选择一个页面来显示不起作用的帖子。第二个是 getpost 插件,它使用短代码 [get_posts] 显示帖子,它只显示短代码并且插件处于活动状态。
我希望它看起来像这样 http://www.completesource.co.uk/category/ironkey-id-theft/ 但在此页面上 http://beta.completesource.co.uk/it-news/
我一直在寻找这个,任何帮助将不胜感激。
谢谢
编辑:代码
<?php
if (is_page() ) {
$category = get_post_meta($posts[0]->ID, 'category', true);
}
if ($category) {
$cat = get_cat_ID($category);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'category__in' => array($cat),
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => $post_per_page,
'caller_get_posts' => $do_not_show_stickies
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) :
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <? php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_excerpt('Read the rest of this entry »'); ?>
<a href="<?php the_permalink() ?>">Read More..</a>
<BR><BR>
</div>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
<?php endif;
$wp_query = $temp; //reset back to original query
} // if ($category)
?>
【问题讨论】:
-
发布您的代码的代表性(又名 SMALL)示例。否则这个问题基本上是无法解决的。
-
你想看哪一部分?
-
Marc 是对的——我们需要更多信息。我会首先检查您的设置>阅读并验证这些是否适合您的主题。如果您正在滚动自己的主题,请确保您正在调用“循环”而不是显示静态内容。为我们提供帮助:您使用的是什么主题。如果你自己 - 在循环区域/主页中向我们展示一些调用循环的代码。
-
我相信这就是您所要求的。', ''); ?>阅读其余部分此页面的»'); ?> '
Pages: ', 'after' => '
', 'next_or_number' => 'number') ); ?> -
请编辑您的帖子,并将该代码放入正文中,以便我们轻松阅读。
标签: wordpress