Skip to main content

Forums

This topic contains 20 replies, has 0 voices, and was last updated by  tobeeornot 7 years, 10 months ago.

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #91531

    tobeeornot
    Member

    Sorry Doc – I feel a little bad asking you to trawl though my code.


    < ?php

    /*
    Template Name: Home
    */

    ?>
    < ?php get_header(); ?>




    What We Do





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

      < ?php query_posts("posts_per_page=1&post_type=page&page_id=168"); the_post(); ?>


    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>
      leads
      " class="button">View More


    • < ?php query_posts("posts_per_page=1&post_type=page&page_id=236"); the_post(); ?>


    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>



      " class="button">View More


    • < ?php query_posts("posts_per_page=1&post_type=page&page_id=240"); the_post(); ?>



    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>
      customers
      " class="button">View More




    < ?php // comments_template(); ?>

    < ?php endwhile; endif; ?>

    < ?php get_sidebar(); ?>

    < ?php get_footer(); ?>
    #91534

    TheDoc
    Moderator

    I’ve never seen multiple queries in a single loop like that. That’s probably what is causing the custom fields to go wonky. Here’s my version of your template:

    < ?php /* Template Name: Home */ ?>
    < ?php get_header(); ?>



    What We Do





      < ?php query_posts("posts_per_page=1&post_type=page&page_id=168");
      if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>
      leads
      " class="button">View More

    • < ?php endwhile; ?>

      < ?php else: ?>

      < ?php endif; ?>
      < ?php wp_reset_query(); ?>


      < ?php query_posts("posts_per_page=1&post_type=page&page_id=236");
      if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>
      leads
      " class="button">View More

    • < ?php endwhile; ?>

      < ?php else: ?>

      < ?php endif; ?>
      < ?php wp_reset_query(); ?>


      < ?php query_posts("posts_per_page=1&post_type=page&page_id=240");
      if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    • < ?php the_title(); ?>


      < ?php the_excerpt(); ?>
      customers
      " class="button">View More

    • < ?php endwhile; ?>

      < ?php else: ?>

      < ?php endif; ?>
      < ?php wp_reset_query(); ?>




    < ?php // comments_template(); ?>

    < ?php endwhile; endif; ?>

    < ?php get_sidebar(); ?>

    < ?php get_footer(); ?>

    Note that I’m resetting the query after each loop.

    Also, I’ve removed the custom fields altogether, since I really don’t see why you want to use them when you can just link directly to the image in your theme’s folder.

    If you need to link to a custom field, don’t combine the template directory code with the custom field code, I’m sure that was causing some issues as well.

    #91535

    tobeeornot
    Member

    Yes, that is really helpful. I thought the loop had to contain all queries but it makes sense that you would break it up and reset it after it each group.

    Regarding custom fields, isn’t the benefit that they can be changed by the user using the WP back-end?

    #91539

    TheDoc
    Moderator

    Totally, but not if they are linking to images in your theme’s folder that they’d have to upload.

    #91541

    OniLinkCR
    Member

    Yeah, it’s best if you post thumbnails if it isn’t already being used or get a multiple post thumbnails plug in. This way they just upload the image and its inserted.

    #91546

    tobeeornot
    Member

    Ok, but to do that would you simply use a class to ensure the images are located in the right position and would that class need to be wrapped in any code?

Viewing 6 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star