WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Simple php question (8 posts)

  1. peterspliid
    Member
    Posted 1 year ago #

    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!

  2. Andrew Nevins
    Spam zapper & Volunteer Moderator
    Posted 1 year ago #

    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 ''; ?>
  3. peterspliid
    Member
    Posted 1 year ago #

    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.

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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)

  5. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    <?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;?>
  6. peterspliid
    Member
    Posted 1 year ago #

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

  7. Jose Castaneda
    Member
    Posted 1 year ago #

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

  8. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.