Jump to content

PULL Profiles from WordPress Database and Display them on WP Page


JohnLee

Recommended Posts

I am building a WordPress website where I want profiles to be displayed directly on the Home page from the Database as members add their profiles. What I have so far is this:

If anyone register through the website, their info is stored in a database and their profiles are displayed in a result page. For example: if you use the search form and search for specific member they will display in: http://www.website.com/results/URL (Where results is the page that always display results. Here is the code I have that works just fine:

    <style>
    .person_name {
      font-size:13px; text-align:center; text-transform:uppercase; padding-top:8px;
    }
    .person_image {
      padding:4.2px; border:1px solid #aaa; width:125px;
    }
    </style>
    
    <?php $state=$_GET['state'];
    $county=$_GET['county'];
    $city=$_GET['city'];
    $zip=$_GET['zip'];
    
    /**/
    // Make a MySQL Connection
    mysql_connect("localhost", "user", "pass") or die(mysql_error());
    mysql_select_db("user") or die(mysql_error());
    
    // Retrieve all the data from the "example" table
    $result = mysql_query("SELECT * FROM persons WHERE city='".$city."' OR zip='".$zip."' ORDER BY name")
    or die(mysql_error());  
    
    while($row = mysql_fetch_array($result)){
    echo "<div style='display:inline-block;margin-right:15px;cursor:pointer;' onclick='location=\"http://www.website.com/profile/?id=".str_replace(' ','_',$row["name"])."\"'>";
    echo "<div class='person_image'><img src='http://www.website.com/wp-content/uploads/".$row['photo']."' style='' width='125px' /></div>";
    echo "<div class='person_name'>".$row['name']."</div>";
    echo "</div>";
    }
    /**/
    
    //echo "page for: ".$state." ".$county." ".$city." ".$zip;
    ?>

On my home page and where I want the data to be displayed other than the result page is kinda tricky. I want to be able to only display 6 profiles. I also want to mention that I am using the Execute PHP plugin that helped me display the php in pages.

Here is some of my home page code where I want to display those profiles:

    if ( is_active_sidebar( 'Our Newest Members' ) ) {
                echo '<div class="Our Newest Members">';
                echo '<h4>' . __( 'Our Newest Members', 'themename' ) . '</h4>';
                dynamic_sidebar( 'Our Newest Members' );
                echo '</div><!-- end .OurNewestMembers -->';
            }

I am not a code savvy person but always willing to learn and I am also more than happy to answer any follow up questions. Thank you so much for all your help,!!!!

John

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.