Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jeffreyhmartin

    (@jeffreyhmartin)

    That did it! Getting this piece of code working has been the last holdup to going live with the update to my child theme.
    There are several places on the web that explain how to run multiple loops on a page and prevent duplicate posts, but none of them worked without storing this as a global variable.
    Many Thanks!
    I’m going to wait to mark this thread as resolved temporarily just to be sure everything is good.

    Thread Starter jeffreyhmartin

    (@jeffreyhmartin)

    The sidebar in Twenty Ten is called after the main loop.

    I’m still fairly new to WordPress and php. How and where would I declare $do_not_duplicate as global before the main loop?

    Does it involve a change to this code just before the main loop?

    <?php 	$do_not_duplicate = array();
    	while (have_posts()) : the_post();
    	$do_not_duplicate[] = get_the_ID();
     ?>

    Thanks.

    Thread Starter jeffreyhmartin

    (@jeffreyhmartin)

    I changed the variable $ids to $do_not_duplicate everywhere it was in the code, and added the suggested code to the sidebar.php as follows:

    <!-- print out the Post ID, category, and what's stored in the variable $do_not_duplicate -->
    <?php global $do_not_duplicate; ?>
    <p>Result of print_r($do_not_duplicate): <?php print_r($do_not_duplicate) ?></p>
    
    <?php // Create a new instance
    	$third_query = new WP_Query(array('post__not_in' => $do_not_duplicate));
    	// The Loop
    	while( $third_query->have_posts() ) : $third_query->the_post(); ?>
    <?php
    	echo '<li>';
     	the_title();
     	echo '</li>';
    	endwhile;
    	wp_reset_query();
     ?>

    I’m still getting the same output – when the first loop runs on a category page, the output of print_r($do_not_duplicate) is: Array ( [0] => 353 [1] => 321 [2] => 194 [3] => 202 [4] => 112 [5] => 12 [6] => 10 ). But the output of print_r($do_not_duplicate) in the sidebar, just after <?php global $do_not_duplicate; ?> is still empty. Do I need to change anything about how the $do_not_duplicate variable is stored in the original array?

    I had a similar problem of being repeatedly unable to authenticate with Google. In my Google account, I added my domain to the “websites authorized to access your account.” It still didn’t work, nor did any other Google Analytics plugins, which indicated I was missing something obvious here.
    As a first-time user of Google Analytics, I did not realize that I had to create an account at Google Analytics. Once I did that, listed my domain there, got my UA code, and manually entered it in Google Analytics for WordPress, I was good to go. Note that when you’re in Google Analytics, you don’t need to copy and paste the code it gives you into the head of your webpage (your wordpress header.php), because the plugin does that for you.
    If you’re having trouble authenticating, maybe some of you are having this same problem. Sometimes the simplest things are the ones you can’t find any support for, because everyone thinks you already know them (try searching online for a recipe for making simple oatmeal if you forgot the water/oats ratio).

    I read several explanations for how to get the Post Thumbnail function to show up in my Post Editor (WordPress version 3.0.1), and none of them worked until I created a functions.php file in my theme with the following code, as recommended by Matt Brett at https://mattbrett.com/workshop/2010/wordpress-post-thumbnails-revisited/

    <?php
    if (function_exists(‘add_theme_support’)) {
    add_theme_support(‘post-thumbnails’);
    }
    ?>

    Thanks to Matt.

Viewing 5 replies - 1 through 5 (of 5 total)