WordPress.org

Ready to get started?Download WordPress

Forums

Byline
[resolved] Getting to the descriptions (11 posts)

  1. dsolimini
    Member
    Posted 4 months ago #

    First, I love this plugin right now. Implementing co-authors plus was driving me batty and this is a godsend. Thank you.

    A brief question... and please note that while I have a background in SQL and ASP, PHP is not my native language and it's been a while since I dug into a coding project.

    How do I display the description field? At the bottom of my posts, I'd like to loop through each byline and spit out something like:

    About Bob Smith
    Bob Smith is an awesome guy. He does things and stuff.

    About Andrew Anderson
    Andrew is the director of important things at large company.

    etc.

    Assistance is appreciated.

    Best,
    Dave

    https://wordpress.org/plugins/byline/

  2. mattdu
    Member
    Plugin Author

    Posted 4 months ago #

    That's a great idea. I envisioned that when I wrote this but have not gotten around to coding that. BUT you're in luck, I figured it out:

    $terms = get_terms("byline");
                         $count = count($terms);
                         if ( $count > 0 ){
                             echo "<ul>";
                             foreach ( $terms as $term ) {
                               echo "<h6>About " . $term->name . "</h6>";
                               echo "<p>" . $term->description . "</p>";
                             }
                             echo "</ul>";
                         }

    You can replace the HTML markup for anything you prefer and add class names, etc.

    I would drop this in your single.php template or inside whatever handles the display of post-content.

    You can see this magic at work here: http://mattdulin.com/tdcx/duis-sed-nisl-aliquam/

  3. mattdu
    Member
    Plugin Author

    Posted 4 months ago #

    Ignore the UL and replace with a DIV or however else you want to wrap this author listing. If you use UL then you will also need to add
    a LI tag before each H6 and after the closing P tag... you know the drill.

  4. dsolimini
    Member
    Posted 4 months ago #

    You, sir, have made my night. Worked perfectly. And now that I understand get_terms(), I can do additional things with this. Thank you again for such a solid piece of work.

  5. pwocken
    Member
    Posted 4 months ago #

    Hi Matt,

    This is precisely the plugin I've been looking for our new blog! I love its simplicity and its features, except I'm having a hard time getting the author descriptions to show at the end of my post.

    Granted, I'm a little over my head, but I think I found which PHP file (content-single.php) contains the entry-content and get_the_author for my theme (Catch Box). As you can see here, I'm having a hard time trying to figure out where in the content-single.php file to place the code you referenced in your previous post. Do I paste it in between the existing PHP code? Do I replace some of the existing code with your code?

    Again, I apologize for the junior-level question, but I'd love to figure out how to make this work for our blog. Any insights you can offer would be tremendous. Thanks!

  6. mattdu
    Member
    Plugin Author

    Posted 4 months ago #

    The code needs to be inside a php tag.

    To be safe, rather than deleting your old code, you can comment out the old code by placing two forward slashes after the php opening tag but before each line of code, so it might look something like:

    <?php //old code here;
           //more old code ();
           //last line of old code;
           //You can add a comment here, to remind you why there is new code below
           $terms = get_terms("byline");
              $count = count($terms);
              if ( $count > 0 ){
                 echo "<ul>";
                    foreach ( $terms as $term ) {
                         echo "<h6>About " . $term->name . "</h6>";
                         echo "<p>" . $term->description . "</p>";
                                                 }
                  echo "</ul>";
                               }
    ?>
  7. pwocken
    Member
    Posted 4 months ago #

    Thanks, Matt! You're a lifesaver!

    I've got the code to dynamically display the author's name and bio, but it also looks like it displays all of the byline authors I've created (I've created two), even when I've only assigned one byline author in the post builder (down near the tags section). The byline(s) also appear on posts that do not have a byline author identified.

    Any thoughts?

    Thanks!

  8. delawaresmith
    Member
    Posted 3 months ago #

    I added this to my single.php, but then it shows all author and descriptions on all pages. Same issue as pwocken.

    It's a test site, but you can see it live here - http://www.hereismysite.info/monster-santa/

    <?php //old code here;
           //more old code ();
           //last line of old code;
           //You can add a comment here, to remind you why there is new code below
           $terms = get_terms("byline");
              $count = count($terms);
              if ( $count > 0 ){
                 echo "
    <ul>";
                    foreach ( $terms as $term ) {
                         echo "<h6>About " . $term->name . "</h6>";
                         echo "<p>" . $term->description . "</p>";
                                                 }
                  echo "</ul>
    ";
                               }
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  9. esmi
    Forum Moderator
    Posted 3 months ago #

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else's topic.

    This month old topic has been resolved.

  10. mattdu
    Member
    Plugin Author

    Posted 3 months ago #

    OK, this post revealed a flaw in my previous code.

    Replace this line:
    $terms = get_terms("byline");

    With this line:
    $terms = get_the_terms($post->ID, 'byline');

  11. Dan Knauss
    Member
    Posted 1 month ago #

    Matt, your demo site using the 2014 theme displays an extra linked author icon at the head of the byline list since the user-author link is still being displayed with the linked text (your name) removed. That original user-author link ends up enclosing all your byline links:
    <span class="entry-date"><a href="http://mattdulin.com/tdcx/duis-sed-nisl-aliquam/" rel="bookmark"><time class="entry-date" datetime="2014-03-25T03:50:45+00:00">March 25, 2014</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="http://mattdulin.com/tdcx/author/tdcadmin/" rel="author"><a href="http://mattdulin.com/tdcx/byline/firstname-lastname/" rel="tag">Firstname Lastname</a>, <a href="http://mattdulin.com/tdcx/byline/lorem-ipsum-guy/" rel="tag">Lorem Ipsum Guy</a>, <a href="http://mattdulin.com/tdcx/byline/secondname-lastname/" rel="tag">Secondname Lastname</a>, <a href="http://mattdulin.com/tdcx/byline/thirdname-lastname/" rel="tag">Thirdname Lastname</a></a></span></span></div>

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.