WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] div format (27 posts)

  1. rogersundstrom
    Member
    Posted 1 year ago #

    Having problem with my div format

    This code is working and...

    <?php
    $last_band = null;
    foreach ( $bandinfo as $infoband ) : ?>
    
        <?php if ($last_band != $infoband['band1']): ?>
            <h3><?php echo $infoband['band1']; ?></h3>
        <?php endif; ?>
    
        <?php echo $infoband['lineup']; ?> <?php echo $infoband['year']; ?><br>
    
    <?php
        $last_band = $bandinfo['band1'];
    endforeach; ?>

    it gives me this result
    Band1
    lineup1 year1
    lineup2 year2
    lineup3 year3

    Band2
    lineup1 year1
    lineup2 year2
    lineup3 year3

    Now I want this format instead
    Band1
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    Band2
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    and have tried this code but only get errors like
    Parse error: syntax error, unexpected T_AS in ...

    <?php
    $max = count($bandinfo);
    for ( $i = 0; $i < $max; $i++) $bandinfo as $infoband ) :
        $infoband = $bandinfo[$i];
    ?>
    
        <?php if ($i == 0 || $bandinfo[$i-1]['band1'] != $infoband['band1']): ?>
            <h3><?php echo $infoband['band1']; ?></h3>
            <div class="bandinfo">
        <?php endif; ?>
    
        <?php echo $infoband['lineup']; ?> <?php echo $infoband['year']; ?><br>
    
    <?php
         <?php if ($i == $max-1 || $bandinfo[$i+1]['band1'] != $infoband['band1']): ?>
            </div>
        <?php endif; ?>
    endforeach; ?>

    Have anyone some suggestion?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Can you provide the full error please?

  3. rogersundstrom
    Member
    Posted 1 year ago #

    Parse error: syntax error, unexpected T_AS in /home/angelita/public_html/eme/eme/wp-content/plugins/pods/components/Pages.php(480) : eval()'d code on line 119

    and line 119 are "for ( $i = 0; $i < $max; $i++) $bandinfo as $infoband )" :

  4. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Looks like an issue with wp-content/plugins/pods/ plugin...use well used and popular plugins only...

  5. rogersundstrom
    Member
    Posted 1 year ago #

    Can be so, but I think Pods are well used and popular plugins.
    http://wordpress.org/extend/plugins/pods/

    I see I have one ")" to much in that line and have removed it but with same result.
    I think I doing something wrong here
    for ( $i = 0; $i < $max; $i++) $bandinfo as $infoband :
    $infoband = $bandinfo[$i];
    ?>

  6. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    That's an error that comes out when PHP runs inside an eval() but is malformed.

    This line is invalid:

    for ( $i = 0; $i < $max; $i++) $bandinfo as $infoband ) :

  7. rogersundstrom
    Member
    Posted 1 year ago #

    Hi Scott,
    How to do it right then?

    I want this result

    Band1
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    Band2
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    Instead of this
    Band1
    lineup1 year1
    lineup2 year2
    lineup3 year3

    Band2
    lineup1 year1
    lineup2 year2
    lineup3 year3

  8. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Good SEO can get a plugin to 100K here - a good plugin has 3M+ downloads...
    http://wordpress.org/extend/plugins/browse/popular/

  9. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Maybe this?

    <?php
    $last_band = null;
    foreach ( $bandinfo as $infoband ) : ?>
    
        <?php if ($last_band != $infoband['band1']): ?>
            <h3><?php echo $infoband['band1']; ?></h3>
            <div>
        <?php endif; ?>
    
        <?php echo $infoband['lineup']; ?> <?php echo $infoband['year']; ?><br>
    
        <?php if ($last_band != $infoband['band1']): ?>
            </div>
        <?php endif; ?>
    
    <?php
        $last_band = $bandinfo['band1'];
    endforeach; ?>
  10. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Seacoast Web Design, Pods is well known and popular, and has 114k downloads right now. A good plugin does not have to have 3M+ downloads, that's irrelevant and there are lots of bad plugins out there with tons of downloads.

  11. rogersundstrom
    Member
    Posted 1 year ago #

    That plugin with 5M+ downloads don't help me right now :-)
    I´m working with pods now and as Scott says my line is malformed and invalid. So with correct code I´m on...

  12. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    I'm the lead developer on the Pods Framework project, Roger, just let me know if you have any further problems, I'll help if I've got the time. I usually keep an ear out for any mentions of Pods so I can provide support.

  13. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Pods, can you add a link to your WP support?

  14. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Here it is: http://wordpress.org/support/plugin/pods

    Again - just because some download it, does not mean they use it...based on forum support questions over a long period, I say few use it...

  15. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    We have a pretty active forum over at http://podsframework.org/forums/

    We run our own forums separate from the WP support forums, but continue to support threads started on our WP support forums.

  16. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    It's pretty?

  17. rogersundstrom
    Member
    Posted 1 year ago #

    Thanks Scott :-)
    It didn't work. Now I got </div> after first lineup every new Bandx

  18. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    I'm using "pretty" as an adverb here.

  19. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Roger, both WP and many themes or plugins may strip some html tags - please be clear about how you are doing this....

  20. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    <?php
    $bands = array();
    
    foreach ( $bandinfo as $band ) {
        if ( !isset( $bands[ $band[ 'band1' ] ] ) )
            $bands[ $band[ 'band1' ] ] = array();
    
        $bands[ $band[ 'band1' ] ][] = $band;
    }
    
    foreach ( $bands as $group => $band_group ) {
    ?>
        <h3><?php echo $group; ?></h3>
    
        <div>
            <?php foreach ( $band_group as $band ) { ?>
                <?php echo $band[ 'lineup' ]; ?> <?php echo $band[ 'year' ]; ?><br>
            <?php } ?>
        </div>
    <?php
    }
    ?>
  21. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Just updated my reply with a fix to the logic, should be good now.

  22. rogersundstrom
    Member
    Posted 1 year ago #

    Didn't work out. Now I get this

    Band1
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band4
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band4
    <div>
    Lineupx Yearx
    </div>

    Band5
    <div>
    Lineupx Yearx
    </div>

  23. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    How is your code being called? Can you provide the rest?

  24. rogersundstrom
    Member
    Posted 1 year ago #

    In this case Band1 have 6 lineups
    and Band2-Band5 have 1 lineup

    Now he list bands more than one and in a weird order.

  25. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Where are you getting $bandinfo?

  26. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Resolved with Roger in our 'not good' plugin's chat room in real time.

  27. rogersundstrom
    Member
    Posted 1 year ago #

    Here is the working code :-)

    <?php $bands = array(); ?>
    
    <?php foreach ( $bandinfo_data[0] as $bandsattning => $bandinfo ) : ?>
    <?php foreach ( $bandinfo as $band ) {
        if ( !isset( $bands[ $band[ 'band1' ] ] ) )
            $bands[ $band[ 'band1' ] ] = array();
    
        $bands[ $band[ 'band1' ] ][] = $band;
    }
    ?>
    <?php endforeach; ?>
    
        <?php
    
    foreach ( $bands as $group => $band_group ) {
    ?>
        <h3><?php echo $group; ?></h3>
    
        <div>
            <?php foreach ( $band_group as $band ) { ?>
                <?php echo $band[ 'lineup' ]; ?> <?php echo $band[ 'year' ]; ?><br>
            <?php } ?>
        </div>
    <?php
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags