• Dose this code look ok

    <?php  get_header(); ?>
    <div id="content">
    	<?php if (is_single() || is_category() || is_archive()) {get_sidebar();} ?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php if (!is_page()) { ?>
    
        <div class="post-headline">
    	<h2>
    	  <?php if( !is_single() AND !is_page() ) { ?> <a href="<?php the_permalink() ?>" >
    	  <?php } the_title(); if( !is_single() AND !is_page() ) { ?></a> <?php } ?>
    	</h2>
        </div>
    
    	<?php } ?><?php if(is_category() || is_archive()) { the_excerpt(); } else { the_content(); } ?><?php endwhile; ?>
    	<?php posts_nav_link(' - ','« Prev','Next »') ?>
    	<?php if (is_single()) {comments_template();} ?>
    	  <?php else : ?><?php endif; ?>
    </div>
    <?php   get_footer(); ?>

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter tom-kroscavage

    (@tom-kroscavage)

    Is minimal faster?

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    I made a few changes is it safe? Do I need more “end if”s?

    <?php  get_header(); ?>
    <?php if (is_single() || is_category() || is_archive()) {get_sidebar();} ?>
     <div id="content">
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php if (!is_page()) { ?>
    
    	<h2><?php if( !is_single() AND !is_page() ) { ?> <a href="<?php the_permalink() ?>" ><?php } the_title(); if( !is_single() AND !is_page() ) { ?></a> <?php } ?></h2>
    
    	<?php } ?><?php if(is_category() || is_archive()) { the_excerpt(); } else { the_content(); } ?><?php endwhile; ?>
    	<?php posts_nav_link(' - ','? Prev','Next ?') ?>
    	<?php if (is_single()) {comments_template();} ?>
    	  <?php else : ?>Nothing Here<?php endif; ?>
     </div>
    <?php   get_footer(); ?>
    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    will this work?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Stop bumping.

    If it works, it works. I don’t know if it’d be significantly faster. You’d have to run some tests.

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    [Moronic expletive deleted]

    I would like to do something like that.

    It only calls comment.php if it is a single post? Tom can you comment the code for me? Can I use it?

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    Sure Sharolyn start saving your money it aint gonna be cheap. Here’s the code. I guess I’m the php expert around here.

    <?php  get_header(); ?>// Call the header.php
    <?php if (is_single() || is_category() || is_archive()) {get_sidebar();} ?>// Call the sidebar if its not a page
    
     <div id="content">
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>// The print post loop
    	<?php if (!is_page()) { ?>// Pages jump out of the loop here 
    
    	<h2> <?php if( !is_single() AND !is_page() ) { ?> <a href="<?php the_permalink() ?>" > <?php } the_title(); if( !is_single() AND !is_page() ) { ?> <?php } ?></h2>//  List post title links
    
    	<?php } ?><?php if(is_category() || is_archive()) { the_excerpt(); } else { the_content(); } ?>// List the excerpts or full content for posts
    	<?php endwhile; ?>// end of loop
    	<?php posts_nav_link(' - ','« Prev','Next »') ?> // Prev Next post page links
    	<?php if (is_single()) {comments_template();} ?> // Call comments.php if it is a post
    	  <?php else : ?>Nothing Here<?php endif; ?> // bad url
     </div><--End content div-->
    <?php   get_footer(); ?>// Call the footer.php

    you can save a few bits:

    if (is_single() || is_category() || is_archive())

    category is always archive, so this does the same:

    if (is_single() || is_archive())

    same here: if(is_category() || is_archive())
    simplifies to: if(is_archive())


    the <a tag needs closing:

    <h2> <?php if( !is_single() AND !is_page() ) { ?> <a href="<?php the_permalink() ?>" > <?php } the_title(); if( !is_single() AND !is_page() ) { ?></a> <?php } ?></h2>//  List post title links

    instead of if( !is_single() AND !is_page() ) you could try the if( !is_singular() ) conditional tag in the above.

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    Thanks alchymyth it works perfect after I fixed my comments. Here it is

    Pages don’t jump out of the loop where I have them marked, do they?

    if your code exeeds 10 lines, please paste the code into a https://pastebin.com/ and post the link to it here.
    a:
    makes it easier to follow the thread;
    b:
    adds line numbers, keeps the formatting, adds syntax highlighting (if ticked properly at the bottom before submitting the pastebin), makes replying with additions/changes easy, …

    as far as i could follow your code, pages would just jump the h2 title, and are back at the beginning of this line: <?php } ?><?php if(is_category() || is_archive()) { the_excerpt ...

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    Thanks again alchmyth that helps. Here it is in the paste bin
    index.php

    So if its a page this <?php if (!is_page()) { ?>
    jumps to this curly bracket? <?php } ?>

    So if its a page this jumps to this curly bracket?

    yes

    it is quite diffficult to think ahead for every possible situation – that is where testing and debugging comes in.

    for instance, looking at your template again, it might be useful to rewrite this line:
    <?php if (is_single() || is_archive()) {get_sidebar();} ?><!--Call the sidebar if its not a page-->
    into what the comment actually says:
    <?php if (!is_page()) {get_sidebar();} ?><!--Call the sidebar if its not a page-->
    otherwise the sidebar might not get added on the home page for instance, or on attachment pages …

    Thread Starter tom-kroscavage

    (@tom-kroscavage)

    Dude! I like it.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Minimal index.php; Is the code solid?’ is closed to new replies.