• Resolved peterspliid

    (@peterspliid)


    Hi, i’m not very experienced with php yet, and i’m trying to merge two php codes into each other, but I’m running out of luck.

    I have the following code:

    <?php if ( $format == 'gallery' ) echo '
    <div id=spotlightg>
    Contributer Spotlight
    </div>
    <div id=gcontent>
    Info
    </div>
    <br /><br /><br />'; else echo ''; ?>

    And where is says info (between two divs), I want to add this code

    <header class="entry-header">
    		<?php do_action( 'gpp_before_title' ); ?>
    		<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gpp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    		<?php do_action( 'gpp_after_title' ); ?>
    	</header>

    This code contains html and php, so it can’t all be in an echo, due to the php part. I just need this to be between those two divs. How do i manage to do this?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Is this what you mean?

    <?php if ( $format == 'gallery' ) echo '
    <div id=spotlightg>
    Contributer Spotlight
    </div>
    <header class="entry-header">
    		<?php do_action( 'gpp_before_title' ); ?>
    		<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gpp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    		<?php do_action( 'gpp_after_title' ); ?>
    </header>
    <div id=gcontent>
    Info
    </div>
    <br /><br /><br />'; else echo ''; ?>

    Thread Starter peterspliid

    (@peterspliid)

    I know how to copy and paste, but the formatting is wrong. Firstly, you can’t have <?php ?> tags within another tag, secondly, it’s in an echo tag.

    one possibility, getting rid of the echo all together:

    <?php if ( $format == 'gallery' ) : ?>
    <div id=spotlightg>
    Contributer Spotlight
    </div>
    <div id=gcontent>
    <header class="entry-header">
    		<?php do_action( 'gpp_before_title' ); ?>
    		<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gpp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    		<?php do_action( 'gpp_after_title' ); ?>
    	</header></div>
    <br /><br /><br />
    <?php endif; ?>

    (no empty ‘else’ part needed)

    <?php if ( $format == 'gallery' ) :?>
    <div id=spotlightg>
    Contributer Spotlight
    </div>
    <div id="gcontent">
    <header class="entry-header">
    <?php do_action( 'gpp_before_title' ); ?>
    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gpp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    <?php do_action( 'gpp_after_title' ); ?>
    </header>
    </div>
    <br /><br /><br />';
    else:
    echo '';
    endif;?>
    Thread Starter peterspliid

    (@peterspliid)

    That’s exactly what I was looking for. Thanks a lot!

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    alchymyth and esmi beat me to it. Lol. Either way works.

    you can of course keep as much echo as you like:

    <?php if ( $format == 'gallery' ) { echo '
    <div id=spotlightg>
    Contributer Spotlight
    </div>
    <div id=gcontent>
    <header class="entry-header">';
    do_action( 'gpp_before_title' );
    echo '<h1 class="entry-title"><a href="'; the_permalink(); echo '" title="'; printf( esc_attr__( 'Permalink to %s', 'gpp' ), the_title_attribute( 'echo=0' ) ); echo '" rel="bookmark">'; the_title(); echo '</a></h1>';
    do_action( 'gpp_after_title' );
    echo '</header>
    </div>
    <br /><br /><br />';
    } else { echo ''; }
    ?>

    and there are possibly hundreds more of different ways to do it.

    I know how to copy and paste, but the formatting is wrong. Firstly, you can’t have <?php ?> tags within another tag, secondly, it’s in an echo tag.

    should you not be able to do it yourself with that knowledge?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Simple php question’ is closed to new replies.