• I have a theme that I am building on my demo server. The web address is entechpc.com. (I built this entirely from scratch as a noob dev so please don’t laugh at my work)I have a page under the “Our Team” drop down button for “Agents” that displays like a portfolio and when you click on the agents picture it takes you to a page that tells you about that agent. At the bottom of the agent page I have a list of posts by that agent. However, I just noticed that that it only lists the posts that I made, not the posts by the agent. So here is my question.
    I want to know if it is possible to make the list of posts be generated by the agents name instead of my posts. and here is how it should work.
    1. I log in to admin –
    2. I create an agent under add new user – note; I will do this manually there will be no way for anyone to sign up, log in or do anything.
    3. I add him to the agents portfolio manually
    4. I create the profile or the info page about him
    5. I add some listings that the agent may have for me to list under his name as posts under a category like for rent, for sale or commercial
    6. when someone looks at the agent info or profile page the list of his posts displays at the bottom and not mine, lol.

    Im not sure if this is right but I am trying to do it via the permalink now and its not working. Meaning I am trying to make it so Wp picks up the username in the link and goes off that, but like i said its not working. Any help would be appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ayman

    (@aymanalzarrad)

    If I’m not mistaken you could do something like this:

    <?php
    /**** Get the Information from URL ****/
          // Extract keys from URL
          $keys=parse_url("https://entechpc.com/portfolio/james-g");
    
          // Select the path from URL
          $path_key=explode('/', $keys['path']);
    
    /**** Use the user name from the URL ****/
          // Get the user ID from the name we retrieved from the URL
          $user = get_user_by( 'login', $path_key[count($path_key)-1] );
    
          // Query Posts for that user
          query_posts('author='. $user->ID);
    ?>
    <?php /**** The posts loop ****/ ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        // The title of the posts
         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_quary(); ?>

    Note: I didn’t try it, so please let me know if you try it.

    Thread Starter Keyboard_Headaches

    (@keyboard_headaches)

    Thanks Ayman, I gave this a shot and it did bring up the listings on the single agents page… but it brought up the same listings for every agent, not like I was hoping. lol. I need a way to list the listings that the specific agent has listed or “posted”.
    Unless I mis-understood something in your code or something I was supposed to change in it, it just didn’t do it, lol. I guess I am going to have to hire someone to do it for me, lol.

    Ayman

    (@aymanalzarrad)

    you have to change the first line of code and add another to make the URL dynamic so you could do something like this:

    Add this to your funtions.php file:

    function get_current_Url() {
      $url  = @( $_SERVER["HTTPS"] != 'on' ) ? 'https://'.$_SERVER["SERVER_NAME"] :  'https://'.$_SERVER["SERVER_NAME"];
      $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
      $url .= $_SERVER["REQUEST_URI"];
      return $url;
    }

    Than go back the previous code and Change this:

    /**** Get the Information from URL ****/
          // Extract keys from URL
          $keys=parse_url("https://entechpc.com/portfolio/james-g");

    to this:

    /**** Get the Information from URL ****/
    // Save the URL in a variable
    $current_page = get_current_Url();
    
    // Extract keys from URL
    $keys=parse_url($current_page);

    Now on each page the code will get the URL which contain the user name and than will process the quary_posts for that user

    Thread Starter Keyboard_Headaches

    (@keyboard_headaches)

    lol, I hate to say it but its still not working properly. It always pulls the posts of the site admin. Not sure what to do with it now, ??

    Ayman

    (@aymanalzarrad)

    Did you try the code while logged out?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can this be done in WordPress?’ is closed to new replies.