• I use jquery ajax tabs to load custom loops, but I have a problem with page ID on the li tabs when open, they dont’t act like global $post.

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery UI Tabs - Content via Ajax</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css">
      <script>
      $(function() {
        $( "#tabs" ).tabs({
          beforeLoad: function( event, ui ) {
            ui.jqXHR.fail(function() {
              ui.panel.html(
                "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                "If this wouldn't be a demo." );
            });
          }
        });
      });
      </script>
    </head>
    <body>
    
    <div id="tabs">
      <ul>
        <li><a href="#tabs-1">Preloaded</a></li>
        <li><a href="../ajax/content1.php">Tab 1</a></li>
        <li><a href="../ajax/content2.php">Tab 2</a></li>
        <li><a href="../ajax/content3.php">Tab 3 (slow)</a></li>
        <li><a href="../ajax/content4.php">Tab 4 (broken)</a></li>
      </ul>
      <div id="tabs-1">
        <p>Proin elit ...</p>
      </div>
    </div>
    </body>
    </html>

    This tabs are on my pages, and here’s one page code example: ../ajax/content3.php (placed on website root, folder ajax)

    <?php define('WP_USE_THEMES', false);
    require('../wp-load.php');
     global $post;
     ?>
    <?php
    // this should be for example like $posttags = get_the_tags('16601'); and the loop will work
    $posttags = get_the_tags($post->ID);
    if ($posttags) {
        foreach ($posttags as $tag) {
            query_posts('cat=20"&showposts=30"&tag=' . $tag->slug . '');
        }
    }
            if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <div class="spotlightwrapperbig-featured-left-index">
                        <div class="ptitle-index-featured-left">
                            <div style="font-weight: bold;font-size: 15px;"><a>" rel="bookmark"><?php the_title(); ?></a></div><?php the_content_limit(200, "[...]"); ?></div>
                        <a>" rel="bookmark" title="<?php the_title_attribute(); ?>"><span class="teaser-image-small"><?php the_post_thumbnail('latestgamingupdates', array('class' => 'index-news-featured-left')); ?></span></a>
                    </div>
    			<?php endwhile; else: ?>
            <?php endif; ?>

    I need the current page $post->ID, for my loop to proper work.

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

  • The topic ‘Get $post->ID on another php file’ is closed to new replies.