0
votes

I have a problems using wordpress. I'm editing wordpress page online and using array in it, so when I wrote this on my page,

<section id="recent">
    <h1>Recently Added</h1>
    <ul class="row-fluid">
    <?php
        $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 4, 'orderby' =>'date','order' => 'DESC' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <li class="span3">    
                    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="65px" height="115px" />'; ?>
                        <h3><?php the_title(); ?></h3>
                           <span class="price"><?php echo $product->get_price_html(); ?></span>
                    </a>
                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
            </li><!-- /span3 -->
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    </ul><!-- /row-fluid -->
</section><!-- /recent -->

The result, is the page is showing this instead what I wished for,

‘product’, ‘stock’ => 1, ‘posts_per_page’ => 4, ‘orderby’ =>’date’,’order’ => ‘DESC’ ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?> ‘; ?> get_price_html(); ?>

post, $product ); ?>

Please help me understand what is happening, and how to solve it. At least I know that in this part of the codes,

$args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 4, 'orderby' =>'date','order' => 'DESC' );

The first '>' symbol, close the php tag

1
Unless you have a typo and it's ?>. A greater than symbol is not a valid php close tag. What is the name of the file it is in?Tristan
The => in the array definition is the first closing > in the file, which suggests it has not been sent to the PHP interpreter. If you view the page source in the browser, you will see all the PHP code there. Are you viewing this with a web server, via http://localhost, or attempting to open the file in the browser like file:///path/to/filename?Michael Berkowski
im editing it on the online host, so maybe it is close to localhost, editing it using wordpress editorAgung Kessawa
What do you mean editing it using wordpress editor? You want to say you put php code in your page in wordpress backend? Because that won't work no matter what you tried. Your code looks ok, but should be in a .php file, not in wordpress page. Also don't use wp_reset_query(), instead, use wp_reset_postdata().dingo_d

1 Answers

0
votes

I think you should use curly braces for the if/else clause in this line:

<?php if (has_post_thumbnail( $loop->post->ID )) { echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); } else { echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="65px" height="115px" />'; } ?>