Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    Here’s the pertinent part of the plugin

    do_action( 'simple_user_listing_before_loop', $query_id );
    
    // the user listing loop
    if ( ! empty( $users ) )	 {
    	$i = 0;
    	// loop through each author
    	foreach( $users as $user ){
    		$user->counter = ++$i;
    		sul_get_template_part( 'content', 'author' );
    	}
    } else {
    	sul_get_template_part( 'none', 'author' );
    } //endif
    
    // after the user listing loop
    do_action( 'simple_user_listing_after_loop', $query_id );

    You will need open and close your table on the simple_user_listing_before_loop and simple_user_listing_after_loop hooks. And you will need to override the content-author.php and none-author.php templates with the table rows. See the FAQ for template overrides instructions.

    That’s the best I can do as I don’t provide customization support. Good luck. And feel free to share your solution for any other users.

    Here’s what I use that works. However, there’s one big problem:

    I have template overrides in my theme (like the FAQ directs), but I have to manually edit the plugin file everytime there is an update to the plugin (because it is overwritten). Is there a way to insert some basic html into the simple_user_listing_before_loop outside of the actual plugin file? Like could I use some php in the template override to populate the function?

    My content-author.php

    global $user;
    
    $user_info = get_userdata($user->ID);
    ?>
    	<tr>
    	<td><?php echo get_avatar( $user->ID, 50 ); ?></td>
    	<td><a href="<?php echo get_author_posts_url($user->ID); ?>"><?php echo get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true ); ?></a></td>
    
    <td><a href="mailto:<?php echo get_usermeta($user->ID,'user_email',true); ?>"><?php	echo get_usermeta($user->ID,'user_email',true)?></a></td>
    
    <td><?php
    $value = get_cimyFieldValue($user->ID, 'PHONE');
    	echo cimy_uef_sanitize_content($value);
    ?></td>
    </tr>

    I’m working on swapping the <td> for some css tables, but I’ll still have the same issue not being able to create a header row in the table.

    And this is what I had to do to my simple-user-listing.php file:

    // before the user listing loop
    			do_action( 'simple_user_listing_before_loop', $query_id );
    
    echo"<table>
      <thead>
        <tr>
          <th></th>
          <th>Name</th>
          <th>Email</th>
          <th>Phone</th>
        </tr>
      </thead>
      <tbody class=alumni>";

    and

    // after the user listing loop
    			do_action( 'simple_user_listing_after_loop', $query_id );
    
    echo "</tbody></table>";
    sul_get_template_part( 'navigation', 'author' );
    Plugin Author HelgaTheViking

    (@helgatheviking)

    Use the simple_user_listing_before_loop and simple_user_listing_after_loop hooks…. that’s exactly what they are there for. Here’s a tutorial I wrote introducing action hooks but you can find plenty more info out there.

    In your theme’s functions.php:

    function kia_open_sul_table(){
     echo"<table>
      <thead>
        <tr>
          <th></th>
          <th>Name</th>
          <th>Email</th>
          <th>Phone</th>
        </tr>
      </thead>
      <tbody class=alumni>";
    }
    add_action( 'simple_user_listing_before_loop', 'kia_open_sul_table' );
    
    function kia_open_sul_table(){
      echo "</tbody></table>";
    }
    add_action( 'simple_user_listing_after_loop', 'kia_close_sul_table' );

    Plugin Author HelgaTheViking

    (@helgatheviking)

    duplicate

    @helgatheviking, you are awesome!

    Note, your code has an error though, you define the kia_open_sul_table twice (which causes a fatal error on WP). It should read:

    function kia_open_sul_table(){
     echo"<table>
      <thead>
        <tr>
          <th></th>
          <th>Name</th>
          <th>Email</th>
          <th>Phone</th>
        </tr>
      </thead>
      <tbody class=alumni>";
    }
    add_action( 'simple_user_listing_before_loop', 'kia_open_sul_table' );
    
    function kia_close_sul_table(){
      echo "</tbody></table>";
    }
    add_action( 'simple_user_listing_after_loop', 'kia_close_sul_table' );

    For some cleaner code all around, here is what I have now to make a pretty table:

    content-author.php

    global $user;
    
    $user_info = get_userdata($user->ID);
    ?>
    	<div class="table-row">
    
    	<div class="col-avatar"><?php echo get_avatar( $user->ID, 50 ); ?></div>
    	<div class="col-name"><a href="<?php echo get_author_posts_url($user->ID); ?>"><?php echo get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true ); ?></a></div>
    
    <div class="col-email"><a href="mailto:<?php echo get_usermeta($user->ID,'user_email',true); ?>"><?php	echo get_usermeta($user->ID,'user_email',true)?></a></div>
    
    <div class="column"><?php
    $value = get_cimyFieldValue($user->ID, 'PHONE');
    	echo cimy_uef_sanitize_content($value);
    ?></div>
    
    </div>

    Added to my functions.php file:

    function kia_open_sul_table(){
     echo '<div class="Table">
        <div class="Heading">
    	<div class="col-avatar"></div>
    	<div class="col-name">Name</div>
    	<div class="col-email">Email</div>
    	<div class="column">Phone</div>
        </div>';
    }
    add_action( 'simple_user_listing_before_loop', 'kia_open_sul_table' );
    
    function kia_close_sul_table(){
     echo '</div>';
    }
    add_action( 'simple_user_listing_after_loop', 'kia_close_sul_table' );

    My CSS to support it:

    .Table {
    	display: table;
    }
    
    .Heading {
    	display: table-row;
    	font-weight: bold;
    	text-align: center;
    }
    
    .table-row {
    	display: table-row;
    }
    
    .column, .col-name, .col-email, .col-avatar {
    	display: table-cell;
    	border: solid;
    	border-width: thin;
    	vertical-align: middle;
    	padding-left: 5px;
    	padding-right: 5px;
    }

    *Note, you don’t need to define the columns using different classes as I did, but I have specific requirements to display them differently (i.e. hide them on smaller displays, etc.)

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Oopss…copy/paste error, good catch. And cool share! Though if you are actually displaying tabular data, you may as well use <table> elements.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display results in table’ is closed to new replies.