1

I'm displaying just post titles, and excerpt and categories on the home page of a site. I'm pulling from several different post types and I have that working correctly. But how do I display the post type and category links? Here's the code I'm using. I've commented where I'd like those links to show. Here's a screenshot of where those links should appear: http://prnt.sc/c2cl3g

(Thanks Dan, for the editing help link. A simple ctrl-k keyboard command fixed the issue.)

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);

/**
 *
 * Template Name: Home
 *
 */
 get_header(); ?>

<div class="fl-archive container">
    <div class="row">

        <?php FLTheme::sidebar('left'); ?>

        <div class="fl-content <?php FLTheme::content_class(); ?>" itemscope="itemscope" itemtype="http://schema.org/Blog">




<?php FLTheme::archive_page_header(); ?>



<?php 

//global $wp_query;

$paged = get_query_var('page') ? get_query_var('page') : 1;
//echo $paged; exit;
$args = array('post_type' => array('post', 'rolodex', 'free_cloud_tools'), 
    'posts_per_page' => 25, 'paged' =>$paged);


/*$args = array_merge(
         $wp_query->query_vars, 
            array(
                'post_type' => array('post', 'rolodex', 'free_cloud_tools'),
                'posts_per_page' => 25,
                )
            );*/
$loop = new WP_Query( $args );

  $max_page = $loop->max_num_pages; 



if($loop->have_posts()) : ?>
<?php while($loop->have_posts()) : $loop->the_post(); ?>    


<div id="home-content-wrap">
<h1 class="home-title"><a href="<?php the_permalink(); ?>"><?php  the_title(); ?></a>  <br><span class="home-meta"> Found in <?php $obj = get_post_type_object( $post->post_type );
/** NEED THE POST TYPE ARCHIVE LINK TO DISPLAY BELOW **/
if($obj->labels->singular_name == 'Post')
{
    echo 'Blog';
}
else if($obj->labels->singular_name == 'Rolodex Entry')
{
    echo 'Rolodex';
}
else if($obj->labels->singular_name == 'Free Cloud Tool')
{
    echo 'Free Cloud Tools';
}
else
{
    echo $obj->labels->singular_name; 
}
?>
/** NEED CATEGORY LINK TO SHOW HERE **/
| Categories: <?php $tax = get_post_taxonomies( $post->ID ); 

//print_r($tax);
$cat_array = array();
 foreach($tax as $taxonomy)
 {
    //print_r($taxonomy) ;  
    if(is_taxonomy_hierarchical($taxonomy))
    {
        $cat = wp_get_post_terms($post->ID, $taxonomy);
         /*echo "<pre>";
         print_r($cat);*/

      foreach($cat as $category){ //echo $category->name.' ,'; 
        $cat_array[] = $category->name;
        //echo $category->name;
        }
    }

 }

 $val = implode(' , ', $cat_array);
 $val = rtrim($val, ' , ');
 echo $val;

    /*the_category( ',' );*/ ?> | <a href="<?php echo get_comments_link(); ?>"><?php echo get_comments_number(); ?> <i class="fa fa-comment"></i> </a> </span> </h1>




<div class="home-excerpt"><?php the_excerpt() ?></div>

</div><!-- end home content wrap -->
<div class="blog-divider"></div>

    <?php endwhile; //wp_reset_query();?>           
                <?php  
                wp_pagenavi( array( 'query' => $loop ) );   //FLTheme::archive_nav(); ?>

            <?php else : ?>

                <?php get_template_part('content', 'no-results'); ?>

            <?php endif; ?>

        </div>

        <?php FLTheme::sidebar('right'); ?>
        <?php wp_reset_postdata(); // always reset post data after a custom query ?>
    </div>
</div>


<?php get_footer(); ?>
  • Please format the code properly! – MinhTri Aug 3 '16 at 16:06
  • Hi Dan. Sorry about that. First time posting here and I thought I followed the directions correctly. It would be helpful if you could clarify how I do that. Thanks. – William Aug 4 '16 at 19:28
  • You should take a look at editting help. – MinhTri Aug 5 '16 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.