PHP Question

by 17 replies
19
Wondering if anyone has any ideas on how to solve a small problem.

I have this code:

Code:
<?php if (!S2MEMBER_CURRENT_USER_IS_LOGGED_IN){ ?>
<a href="<?php echo S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL; ?>">Please subscribe now to continue reading</a>
<a href="<?php echo S2MEMBER_LOGIN_PAGE_URL; ?>">Or Login</a>
<?php } ?>]
This is from the S2Member WP membership plugin.

The part I need help with are the two echo statements. Currently the two options are on two different lines but I would like to have them all on one line if possible just for a little better look.

Any ideas?

Thanks in advance.

Mark
#programming #php #question
  • I take it you mean they're on different lines when viewing the resulting page? You need to look at the styling of anchor 'a' elements in your stylesheet.
    • [1] reply
    • try putting both links on the same line in the PHP code and put a &nbsp; to join them, with no spaces between them.
  • You need to combine the strings into one string


    <a href=
    S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL
    Please subscribe now to continue reading</a><a href=
    S2MEMBER_LOGIN_PAGE_URL
    Or Login</a>

    and output them in one php echo statement (I have to get to a project now and would have to test the code to get it perfect, but the 2 separate php echo statements is what's forcing the line break
  • For example
    PHP Code:
    define("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL","http://www.");
    define("S2MEMBER_LOGIN_PAGE_URL","http://");

    printf("%s",'<a href="'.S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL.'">Please subscribe now to continue reading</a> <a href="'.S2MEMBER_LOGIN_PAGE_URL.'">Or Login</a>'); 
  • I appreciate the responses but for some reason I can't get any of it to work. I tried Robin's solution but couldn't figure out how to get it in one echo statement.

    I'll keep fiddling with it or try to find another workaround. This may be one of those things I have to settle for 2nd or 3rd best in order to get the project finished versus spending forever on a little problem.

    Thanks again.

    Mark
  • Mark, for my example code, be sure to take out the define part

    PHP Code:
    define("S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL","http://www.");
    define("S2MEMBER_LOGIN_PAGE_URL","http://"); 
    that was just there for example purpose
  • Is there any styling being applied to the anchors that would force them onto different lines? i.e. a { display:block; }
  • Code:
    <?php
    if (!S2MEMBER_CURRENT_USER_IS_LOGGED_IN) {
        echo '<a href="' . S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL . '">Please subscribe now to continue reading</a><a href="' . S2MEMBER_LOGIN_PAGE_URL . '">Or Login</a>';
    }
    ?>
    • [1] reply
    • If you can post the URL, I'm pretty sure someone will be able to see the issue. My bet is with the above guesses on CSS styling; the PHP source should still be able to output on two separate lines and display on one.
  • <br /> - is tag for new line in html. New line can be caused by div, p and other tags or style "display: block".
    PHP new line don't mean new line in HTML.

    Most likely parent tag for your links don't have enough width to have links on same line and apply wordwrap.
  • I decided to look into the shortcodes that came with the package versus the PHP - either should work.

    Using the shortcodes I can get both links on the same line so it shouldn't be the CSS.

    Code:
    <a href="[s2Get constant="S2MEMBER_LOGIN_PAGE_URL" /]">Login</a> <a href="[s2Get constant="S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL" /]">Or Signup</a>
    Would still be interesting to know why the PHP didn't work from a learning standpoint.

    Thanks.
    Mark
    • [1] reply
    • Wow. If that's the only difference between the two approaches, it sort of implies that the constant itself has a hard-coded line-break... which certainly shouldn't be the case. Take a close look and compare the source code for the two. Also consider using a tool like Firebug (or simply right-click > Inspect Element in Firefox); I find I learn a lot when I can quickly look how something is being done on the Web.
      • [1] reply
  • Sounds like a lot of work for a tiny tweak of appearance that is not likely to have any effect.
    • [3] replies
    • If it's not css that's the problem then you need to use only one echo like this:

      Code:
      <?php
      if (!S2MEMBER_CURRENT_USER_IS_LOGGED_IN)
      {
          echo ("
                  <a href="S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL;">Please subscribe now to continue reading</a>
                  <a href="S2MEMBER_LOGIN_PAGE_URL;">Or Login</a>
                ")
      }
      ?>
      In the links where a " is used you need to proceed it with \ so it would be \" For some reason when I wrap the code in code tags for the forum it removes them.
    • Perhaps, but he did say he wanted to learn why this was happening.
    • I find that most code is.

      It's really bad when the programmer was not very good. For example, "WordPress" is just the core code. Most of theme themes -- especially most plugins -- are coded by amateurs. So the code tends to be a mess. Some things have really nice markup, but most do not.
  • Banned
    [DELETED]

Next Topics on Trending Feed