首页 文章

将php文件链接到wordpress中的所有按钮

提问于
浏览
-1

category.php 页面中,我按 sub-categries 列出帖子,哪个子类别包含3个以上的帖子,我将显示 VIEW ALL 按钮转到 view-all.php 页面 . 在我的wordpress themes文件夹中,我有一个名为“ view-all.php ”的页面,用于查看特定子类别下的所有帖子 . 但是我不明白如何用一些 parameter 将那个VIEW ALL按钮链接到 view-all.php 页面 . 请帮我提一下你的建议,因为我是wordpress的初学者谢谢

这是 category.php

<?php get_header(); ?>
<?php get_sidebar(); ?>

<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
<?php
// get category ID of particular category
$current_category = single_cat_title("", false);
$category_id = get_cat_ID($current_category);
// end getting category ID

// Get the name of sub-category
$categories =  get_categories('child_of='.$category_id);
foreach  ($categories as $category) {

// Display the sub category information using $category values like $category->cat_name
echo "<div class='sub-category-wrapper'>";
echo '<h3 class="sub-cat-name">&raquo; '.$category->name.'</h3>';

// get number of posts under this sub-category
$total_posts = $category->count;

// Make a loop to display post link which are in this sub category
foreach (get_posts( array(
'category' => $category->term_id,
'orderby' => 'date',
'order'   => 'DESC',
'numberposts' => 3,   // limit number of posts
) ) as $post) {
setup_postdata( $post );
echo "<div class='col-lg-4 col-md-4 col-sm-4 col-xs-12 post-link'>";
echo '<h4 class="title"><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></h4>';
echo '<div class="post-thumb">';
echo '<a href="'.get_permalink($post->ID).'">';
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
echo '</a>';
echo '</div>';
echo "</div>";
}

if( $total_posts > 3 )
{   ?>
<a href="#">View all</a>
<?php   }
echo "</div>";  /* sub-category-wrapper */

}
?>
</div>


<?php get_footer(); ?>

1 回答

  • 0
    <a href="view-all">View all</a>
    

    如果它们位于一个目录中,只需在上面的代码中更改此行

相关问题