Forums

PHP If/Else issue destroys my CSS? (8 posts)

  1. HRTWRK
    Member
    Posted 6 years ago #

    I'm trying to implement a remaindered link feature on my personal site using Matt's Asides hack. The live version of the site right now isn't using the hack, so please refer to the code at the end of this post.

    I have the actual functionality working when I upload the index.php file with the hack in it, but the if/else statement is messing with my layout. Essentially from what I can tell, when you get past the "if" statement, the "else" is ignoring the CSS. (i.e. the header, "if" statement post, and footer are all behaiving correctly, but the "else" statement posts (the majority of my blog) is just unstylized text sitting in between the header and footer).

    Any help or thoughts would be greatly appreciated. I'm new to PHP and WP.

    Here's the index.php file:


    <?php get_header(); ?>

    <?php //if (have_posts()) : while (have_posts()) : the_post();// ?>

    <div class="narrowcolumn">
    <div id="content">
    <div class="post">

    <?php if ($posts) {

    function stupid_hack($str) {
    return preg_replace('|<br/>s*&nbsp;|', '', $str);
    } // end function

    ob_start('stupid_hack');

    foreach($posts as $post) {
    start_wp(); ?>

    <?php if ( in_category(21) && !$single) { ?>

    <div id="link">
    <span class=text><?php echo wptexturize($post->post_excerpt); ?></span>
    <span class="perm"><a href="<?php the_permalink(); ?>" title="Permalink: <?php echo wptexturize(strip_tags(stripslashes($post->post_title), '')); ?>" rel="bookmark">*</a></span><br/>
    <span class=text><?php echo wptexturize($post->post_content); ?></span>&nbsp;&nbsp;&nbsp;<span class=sub><?php edit_post_link('Edit'); ?></span>
    </div><!-- closes "link" -->

    <?php
    }
    else
    { ?>

    <div class="datecolumn">
    <div id="date">
    <?php $d = strtolower(get_the_time('D')); echo ("<img src='http://www.joshuablankenship.com/wordpress/wp-content/themes/deckard/images/w_{$d}.gif'>"); ?>
    <?php $m = strtolower(get_the_time('M')); echo ("<img src='http://www.joshuablankenship.com/wordpress/wp-content/themes/deckard/images/m_{$m}.gif'>"); ?>
    <?php $j = strtolower(get_the_time('j')); echo ("<img src='http://www.joshuablankenship.com/wordpress/wp-content/themes/deckard/images/d_{$j}.gif'>"); ?>
    </div><!-- closes "date" -->
    </div><!-- closes "datecolumn" -->

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

    <div class="entry"><?php the_content('Read the rest of this entry &raquo;'); ?>
    </div><!-- closes "entry" -->

    <p class="postmetadata">Posted at <?php the_time('g:i A') ?> in <?php the_category(', ') ?> |
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link">Permalink</a> |
    <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></p>
    </div><!-- closes "postmetadata" -->

    <?php comments_template(); // Get wp-comments.php template ?>
    </div><!-- closes "post" -->

    <?php } // end else
    } // end foreach loop --> posts
    } // end $post

    else {
    echo '<p>Sorry no posts found.</p>'; } ?>

    <?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>

    </div><!-- closes "content" -->
    </div><!-- closes "narrowcolumn" -->
    <?php get_footer(); ?>

  2. masquerade
    Member
    Posted 6 years ago #

    Matt's asides hack is WP1.2

    Try http://codex.wordpress.org/Adding_Asides

  3. Beel
    Member
    Posted 6 years ago #

    I'd take out the hack, get my page to validate and then add it back in. Right now you have, according to the validator, 159 errors in your xhtml

  4. HRTWRK
    Member
    Posted 6 years ago #

    @ Masquerade - so you're saying this hack won't work in the version of WP i'm running?

    @ Beel - I know it's not trendy to say this, but validating a page isn't on my to-do, so long as it works cross-browser. I'm no web designer.

  5. James
    Happiness Engineer
    Posted 6 years ago #

    @ Masquerade - so you're saying this hack won't work in the version of WP i'm running?

    Yes, he is. Refer to the Codex article that he linked to for instructions on how to do Asides in v1.5. There are also two plugins available for doing Asides under v1.5:

    http://doocy.net/mini-posts/
    http://russ.innereyes.com/wordpress-plugins/

  6. Beel
    Member
    Posted 6 years ago #

    I don't care about the "trendy" either, but validation includes closing open divs, opening closed spans, etc. which obviously impacts the layout. You say asides "messes" with your css, which it wouldn't - but you would if you have done something incorrectly - hence my suggestion to check the validator.

  7. HRTWRK
    Member
    Posted 6 years ago #

    Thanks everyone. I'll look into these plugins.

    @ Beel - And by "messes" I simply mean that after the PHP else tag, it no longer reads the CSS (or at least doesn't include it). The site is live and works minus the hack, hence why I didn't bother (and usually don't nother) with looking at validation. I assumed that the issue was with the hack, not divs or spans, since the site works fine without those lines of code. Thank you for the suggestion.

  8. HRTWRK
    Member
    Posted 6 years ago #

    Hm... using the instructions from the Codex article gives me an error message everytime:

    Parse error: parse error, unexpected '!' ... on line 20

    And i'm confused by the articles statement that part of the code goes after <?php the_date(); ?> since I don't have a tag of that variety anywhere.

    I'm at a loss here. It seems like this should be much simpler than i'm making it.

Topic Closed

This topic has been closed to new replies.

About this Topic