I’ve set up a new wp on an old (outdated site)
The previous site had nice function that created a list with contact persons based on email profiles in the web hotel’s email
I would like to import and reuse this function in the new wp if poossible as a custom fucntion plugin so I don’t need to mess with the pages
The code looked like this:
<div id="contactinfo">
<?php
/*
First we set how we'll want to sort the user list.
You could sort them by:
------------------------
* ID - User ID number.
* user_login - User Login name.
* user_nicename - User Nice name ( nice version of login name ).
* user_email - User Email Address.
* user_url - User Website URL.
* user_registered - User Registration date.
*/
$szSort = "user_nicename";
/*
Now we build the custom query to get the ID of the users.
*/
$aUsersID = $wpdb->get_col( $wpdb->prepare(
"SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC"
, $szSort ));
/*
Once we have the IDs we loop through them with a Foreach statement.
*/
$aExcludedIDs = (1); // IDs of the excluded users.
foreach ( $aUsersID as $iUserID ) :
if ( !in_array( $iUserID, $aExcludedIDs ) )
/*
We use get_userdata() function with each ID.
*/
$user = get_userdata( $iUserID );
echo '<ul class="s_member"><li class="s_name">' . ucwords( strtolower( $user->first_name . ' ' . $user->last_name ) ) . '</li>';
echo '<li class="s_roll">' . $user->user_description . '</li>';
echo '<li class="s_tele"> Telefon:'. ' ' . $user->aim . '</li>';
echo '<li class="s_mail"><a>user_email . '">' . $user->user_email . '</a></li></ul>';
endforeach; // end the users loop.
?>
</div>
I would like to recreate this function on my new page, but don’t really now where to start so would appreciate all help
]]>In WP, create a new page that you will use to display the contact list. It won’t do anything just yet, but you need the page’s ID. Get it from the URL of the edit screen. The URL is something like /wp-admin/post.php?post=123&action=edit. In this example, 123 is the page ID.
Copy the page.php template from your parent theme (or singular.php or index.php if there is no page.php) to the child theme. Rename the file to include the page ID. Using the post=123 as an example, rename the file page-123.php.
Insert you code onto this new page template file. I would put it below the endwhile;
statement used in the page’s main loop, assuming your theme follows the usual method of doing the main loop. Be sure to keep the <?php ?> tags straight.
You will need to add global $wpdb;
right below your code’s <?php
tag.
Now when you view the new page you created, the list should appear.
]]>Thanks for your detailed help!
I have managed to do the new page.php template and uploaded it to my server. Although a bit unsure how to view the new page template
]]>You can verify the page ID by opening the target page for editing. Look at the URL in your browser. It’ll be something like /wp-admin/post.php?post=123&action=edit. In this example, 123 is the ID of the page, even if it is tagged as “post”
]]>