0

I'm new to php and was assigned some code to fix within a Wordpress theme, but I cannot figure it out for anything. The code is for the home page of a custom theme and it is supposed to pull the most recent blog posts and put them in a 3x2 grid at the top of the page.

Here's the page in question

and here's the code from the index.php file (I believe that's where the problem lies)

<?php get_header(); ?>
<?php global $woo_options; ?>
<?php if ( $woo_options['woo_featured_disable'] <> "true" ) include( TEMPLATEPATH . '/includes/featured.php'); ?>
<?php

$t = array();

$t[2] = "A";
$t[5] = "B";

query_posts('post_type=infobox&order=ASC&posts_per_page=20&meta_value=false');

if (have_posts()) :

        $a = array(0,1,3,4); $i = 0;

        while (have_posts()) : the_post();

        $m = "";

        $m .= "<div class=\"bskhp_t\" style='font-family:arial;font-size:12px'>";
        $m .= "<a href=\"".get_post_meta($post->ID, 'mini_readmore', $single = true)."\"><img src=\"".get_post_meta($post->ID, 'mini', $single = true)."\" alt=\"\" class=\"home-icon\"></a>";
        $m .= "<div class=\"bskhp_f\">";
        $m .= "<h3><a href=\"".get_post_meta($post->ID, 'mini_readmore', $single = true)."\">".get_the_title()."</a></h3>";
        $m .= "<p>".get_post_meta($post->ID, 'mini_excerpt', true)."</p>";
        $m .= "<a style='font-family:arial;font-size:13px;text-transform: uppercase' href=\"".get_post_meta($post->ID, 'mini_readmore', $single = true)."\" class=\"btn\">";
        $m .= "<span>Read More</span></a>";
        $m .= "</div>";
        $m .= "</div>";



        $t[$a[$i++]] = $m;

        endwhile;

endif;

$t[2] = $t[0];
$t[3] = $t[0];
$t[4] = $t[0];
$t[5] = $t[0];

This code for some reason will not pull the latest blog posts and put them in the 3x2 grid, except for the first two items, and I have no idea why. I believe the problem is within the get_post_meta function, but my knowledge is too sparse to debug it.

Can anyone help? I would be very gracious :)

2
  • edited to cut down the code and highlight the affected area, code lacks a ?> because I cut it off in the middle of the file
    – Jensen010
    Commented Apr 13, 2015 at 3:08
  • Try to isolate the problem. Convert that query_posts to a new WP_QUERY then var_dump() the query. Do you see the posts you expect?
    – s_ha_dum
    Commented Apr 16, 2015 at 19:13

1 Answer 1

0

First you should make some improvements to your template file. Try this:

<?php get_header(); ?>
<?php global $woo_options; ?>
<?php if ( $woo_options['woo_featured_disable'] <> "true" ) include( TEMPLATEPATH . '/includes/featured.php'); ?>
<?php

$args = array(
    'post_type' => 'infobox',
    'order' => 'DESC', // DESC for newer first.
    'orderby' => 'date',
    'posts_per_page' => 6 // For a 3x2 grid.
);

$latest = new WP_Query( $args ); // You now have an object you can use in 'The Loop'.

if ( $latest->have_posts() ) {
    while ($latest->have_posts()) : $latest->the_post(); ?>

        <div class="bskhp_t">
            <a href="<?php echo get_post_meta($post->ID, 'mini_readmore', true); ?>">
                <img src="<?php echo get_post_meta($post->ID, 'mini', true); ?>" alt="" class="home-icon">
            </a>
            <div class="bskhp_f">
                <a href="<?php echo get_post_meta($post->ID, 'mini_readmore', true); ?>">
                    <h3><?php the_title(); ?></h3>
                </a>
                <p><?php echo get_post_meta($post->ID, 'mini_excerpt', true); ?></p>
                <a href="<?php echo get_post_meta($post->ID, 'mini_readmore', true); ?>">
                    <span>Read more</span>
                </a>
            </div>
        </div>

    <?php endwhile;
}

I removed the CSS since you should move it into another file.

Then, for a 3x2 grid, I suggest you doing so using CSS. Try:

.bskhp_t {
    display: inline-block;
    width: 30%;
}

It's ideal if the parent container of .bskhp_t DIVs takes all available width.

I didn't tested this code so let me know if you had some issues ;)

3
  • Thank you!!!!!! Unfortunately this code worked for a few minutes, but then "broke" and my old issue returned. I have no idea why that would be the case, as there's nothing that I know of overriding this file
    – Jensen010
    Commented Apr 13, 2015 at 14:14
  • If that worked it may still be the right answer ;) Maybe you broke something elsewhere, but I can't help you without more info !
    – Sebastien
    Commented Apr 13, 2015 at 14:18
  • I was wrong, Apparently I had created a home.php file and it was overriding, thank you again! You are a lifesaver!
    – Jensen010
    Commented Apr 13, 2015 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.