Forums

[resolved] PHP inside PHP echo (5 posts)

  1. theronin
    Member
    Posted 2 years ago #

    I'm outputting an echo statement if a conditional check is matched. In this echo statement I have an unordered list

      like this:

      <?php
      $parent_title = get_the_title($post->post_parent);
      if ($parent_title == 'Directors Biographies') {
      echo
      	'<ul id="biogs">
      		<li class="active"><a href="#">Director 1</a></li>
      		<li><a href="#">Director 2</a></li>
      		<li><a href="#">Director 3</a></li>
      		<li><a href="#">Director 4</a></li>
      		<li><a href="#">Director 5</a></li>
      	</ul>';
      }
      ?>

      However where the #'s currently are, I need to insert the following php:

      <?php bloginfo('siteurl'); ?>/company/biographies/index.php?page_id=71

      How can I insert this php block inside another php block without it breaking?

      Or, is there an alternative to grabbing the site url? I've tried /index.php?page_id=71 but because my WordPress installation is in a directory off the root it leaves it out.

      Thanks.

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Example:

    <li><a href="'. get_permalink(71).'">Director 2</a></li>

    71 would be the ID for the page or post, just do the same for each...

  3. theronin
    Member
    Posted 2 years ago #

    Ahh, much simpler than I thought. I knew there would probably be a better way of doing it!

    By the way what is the dot (.) notation for before and after the template tag?

    Thanks for your help.

  4. theronin
    Member
    Posted 2 years ago #

    Ok, I see, just general PHP string concatenation.

    Thanks again.

  5. Mark / t31os
    Moderator
    Posted 2 years ago #

    Yes that's right, just concatenating the echo to include a function call, in this case get_permalink which just returns a value ...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags