• Resolved graphiccontent

    (@graphiccontent)


    Hi guys and gals!

    I am developing a site at the moment that requires quite a lot of code changed to get things working correctly.

    On the page that I am having problems with I am using JS collaspable divs that contain content pulled from certain posts and pages.

    One of the divs pulls in a post title list from a specific category depending on the logged in user. for this I am using the following code –

    <ul>
     <?php
     global $post;
     $myposts = get_posts('numberposts=100&category_name='.$username.'-meetings');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <div class="nextStep"><?php $key="next_step"; echo get_post_meta($post->ID, $key, true); ?></div>
     <?php endforeach; ?>
     </ul>

    So this is pulling in the list from the category called USERNAME-meetings

    this all works fine however I have gone wrong somewhere else in the custom page template and now all other functions to pull in content from the additional fields (more fields plugin) have stopped workin on this page. If I move this div to the last div position in the list it all works again so I think it might have something to do with the <?endforeach; ?>

    here is the full code for this page. I am afraid that this part of the site is password protected and contains confidential info so I can show you the live site, I was just hoping one of experts might be able to tell from looking at it whats causing the issue.

    <?php
    /*
    Template Name: client-page
    */
    ?>
    <?php get_header(); ?>
            <!-- BEGIN WRAPPER -->
        <div id="introwrapper">
            <div id="flags_language_selector"><?php language_selector_flags(); ?></div >
    
            <!-- BEGIN CONTENT -->
            <?php $thetitle = strtolower(get_the_title());
            $shorttitle = str_replace(' ', '', $thetitle);
            $username = ( $userdata->user_login ) ?>
    
            <?php if ( current_user_can( 'level_10' ) || is_user_logged_in() && $username==$shorttitle )  { ?>
    
            <div id="clientcontent">
            <div id="colLeft">
    
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
            <?php the_content(); ?>
    
            <div id="clientLeft">
            <div class="client-menu">
            <!-- DEBREIFING -->
    <h3>Debriefing Agendas & Task Follow Ups</h3>
    <div class="mwInneropen"><div class="text">
    <ul>
     <?php
     global $post;
     $myposts = get_posts('numberposts=100&category_name='.$username.'-meetings');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <div class="nextStep"><?php $key="next_step"; echo get_post_meta($post->ID, $key, true); ?></div>
     <?php endforeach; ?>
     </ul>
    </div></div>
    
    <h3>Market Watch Documents</h3>
            <div class="mwInner">
            <div id="clientSearch">
            <form method="get" id="search" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" value="enter keywords here" name="s" id="search_input" />
    <input type="hidden" name="cat" value="8" />
    <input type="submit" id="searchsubmit" value="Search" />
    </form>
    </div>
    <span id="indicator" style="display:none;">Please wait...</span>
    <div id="searchresults" style="display:none;"></div>
    
            <div class="text">Everyday we scan important business news from the press and upload to our database. Please enter your search keywords in the search bar above or click below to view all documents.<br/><br/><a href="/market-watch-document-list">VIEW ALL DOCUMENTS</a></div>
    
            </div>
    <!-- EVENTS -->
    <h3>Now Boarding | Events within 15 days</h3>
    <div class="mwInner"><div class="text"><?php $key="now_boarding"; echo get_post_meta($post->ID, $key, true); ?></div></div>
    <!-- MARKET WATCH -->
    </div></div>
    <div id="clientRight">
    <div class="client-menu1">
    <!-- MARKET WATCH -->
            <h3>Your Monthly Reports</h3>
    <div class="mwInneropen">
            <div class="text">Below you will find a list of your monthly reports. All are available as downloadable PDFs</div>
            <div class="reportList"><?php $key="monthly_reports"; echo get_post_meta($post->ID, $key, true); ?></div>
            </div>
    
    <!-- FARMING -->
    <h3>Farming Agenda</h3>
    <div class="mwInner"><div class="text"><?php $key="farming_agenda"; echo get_post_meta($post->ID, $key, true); ?></div></div>
    <!-- TESTIMONIALS -->
    <h3>Testimonials</h3>
    <div class="mwInner"><div class="text"><?php $key="testimonials"; echo get_post_meta($post->ID, $key, true); ?></div></div>
    
    </div>
    </div>
    <?php endwhile; endif; ?>
    
            <?php } elseif ( is_user_logged_in()==false ) { ?>
    
                <h2>Sorry...</h2>
    
                    <p>You must be <a href="https://www.lordlouise.com/wp-login.php">logged in</a> to access this area.</p>
    
            <?php } elseif ( is_user_logged_in() && $username!=$shorttitle ) { ?>
    
                <div class="clientcontent">
    
                <h2>Sorry...</h2>
    
                    <p>You are not allowed to access this area.</p>
    
                </div>
    
            <?php } ?>
    
        </div>
        <?php get_sidebar(); ?>    
    
    <?php get_footer(); ?>

    thanks so much in advance
    Matt

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter graphiccontent

    (@graphiccontent)

    Fixed it after some playing!

    <ul>
     <?php
     global $post;
     $tmp_post = $post;
     $myposts = get_posts('category_name='.$username.'-meetings');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <div class="nextStep"><?php $key="next_step"; echo get_post_meta($post->ID, $key, true); ?></div>
     <?php endforeach; ?>
     <?php $post = $tmp_post; ?>
     </ul>

    adding <?php $post = $tmp_post; ?> seemed to do the trick!

    You should be able to use a reset to do the same, i was also going to suggest the problem being the chosen name of the var, ie. $post..

    https://codex.www.ads-software.com/Function_Reference/wp_reset_query

    Should do the same, just look a little more elegant..

    Thread Starter graphiccontent

    (@graphiccontent)

    Hey Mark,

    Yeah good point! I’m getting there with php but still sooooooo much to learn!

    Thanks again
    Matt

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘page display issue’ is closed to new replies.