Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6014677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:43:39+00:00 2026-05-23T02:43:39+00:00

I have a template file ( trendingPosts.php ) for showing 2 latest posts with

  • 0

I have a template file (trendingPosts.php) for showing 2 latest posts with the tag ‘trending’. In the while loop for displaying these 2 posts, I take their ID’s in an array so I can exclude them from the main wordpress loop later:

<div id="trendingWrap" class="clearfix">

<?php
$trending = new WP_Query();
$trending->query("showposts=2&tag=trending");
while($trending->have_posts()) : $trending->the_post();
$wp_query->in_the_loop = true;
$currentTrending[] = $post->ID;
?>

    <div class="trendingStory">
        <h2 class="trendingTitle"><a href="<?php the_permalink(); ?>" alt="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    </div><!-- end trendingStory -->

<?php endwhile; ?>

</div><!-- end trendingWrap -->

The problem is that I have an index.php in which I include the loop.php via get_template_part( 'loop', 'index' ); and I am unable to get the $currentTrending[] array that I made in trendingPosts.php. I need to get that array in my loop.php

Moreover, in my loop.php, I am excluding the 2 posts in the following way.

if(have_posts()): while(have_posts()) : the_post(); 
    if( $post->ID == $currentTrending[0] || $post->ID == $currentTrending[1] ) continue;

Is this the right way to exclude posts? if anybody has a better way of doing this whole thing. Please let me know. Of course nothing works until I manage to get that array in loop.php so that is the main issue.

Thanks! I appreciate all the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:43:40+00:00Added an answer on May 23, 2026 at 2:43 am

    You can easily create variables that you can access everywhere by using the $GLOBALS superglobal array.

    Once set

    $GLOBALS['mytheme_thisismyvar'] = 22;
    

    You can then access it everwhere in the other templates:

    $myvar = $GLOBALS['mytheme_thisismyvar'];
    

    And use it where it suits. This works with sub-templates regardless how they get loaded.

    Because the whole program shares this superglobal array, take care that you do not overwrite existing values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails template (.rhtml file) generating a Javascript object. It looks something
I have a T4 template that generates classes from an xml file. How can
I have this tiny Qt project with a project file like this: TEMPLATE =
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have one freemarker template file which loads all css and js files used
I have to parse this template file ($html) : {$myFirstVariable} {$myMainVar:MYF1,x\:x\,x,2:MYF2:MYF3,false} {$myLastVariable:trim} Following, my
I have he following scenario: Got an HTML template file that will be used
I have the following code to open Excel template file and save it as
I have put some php code in a sidebar-01.php i like in my template
I am running Django trunk and have template Autoescaping on (default). Do I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.