Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

post is not displaying in my static page

I created the code of displaying posts, when i write this , in index.php then it is working fine, please tell me the how can i write this code in my static page in html area i try to write the plugin and create a shortcode and use this shortcode in my static pages,but it is not working I am using the divi theme.

2 Answers

Austin Whipple
Austin Whipple
29,725 Points

Hi Prakash,

This one could get complicated! First things first, you won't have much luck putting PHP code into a WordPress page's HTML editor, it has to be done either in the template of via registered shortcode.

As for creating that shortcode, check out this tutorial on writing a plugin.

Lastly, if you're not necessarily looking for development practice, you could always install a pre-built plugin to do the work for you.

Hi Austin.

I want to use the below code for presenting my post. Actually i am using divi theme and my code is working fine in index.php and not working when i creat a plugin using my code

<!--<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">--> <?php get_header(); ?> <style type="text/css"> .post { width:20%; height:350px; margin-top: 5px; margin-bottom: 30px; margin-right: 5px; margin-left: 5px; /border-radius: 5px;/ //border: 1px dotted #000000; } .post:hover { border: 1px dotted #000000; } .button-0 { width:175%; font-size: 20px; font-weight: 500; //padding: 0.3em 1em; line-height: 1.7em !important; background: #4A96AD; //position: absolute; border: 2px solid; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; -moz-transition: all 0.2s; -webkit-transition: all 0.2s; transition: all 0.2s; color: #ffffff; bottom: 2; } .button-0:hover { border: 1px solid #000000; color: #000000; }

@media (max-width: 768px) { .post{ width:40%; } }

@media (min-width: 768px) { .post{ width:23%; } } </style> <div id="content" role="main">

        <?php //if ( have_posts() ) : ?>

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                    <div class="col-xs-6 col-sm-3 post">
                    <?php $post_format = et_pb_post_format(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
                    <?php
                        $thumb = '';
                        $classtext = 'et_pb_post_main_image';
                        $titletext = get_the_title();
                        $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
                        $thumb = $thumbnail["thumb"];
                        et_divi_post_format_content();
                    //echo "<div class = 'col-xs-6 col-sm-3 post_div'>"; 
                    ?>
                    <a href="<?php the_permalink(); ?>">

<?php $post_format = et_pb_post_format(); if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) { if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) { printf( '<div class="et_main_video_container"> %1$s </div>', $first_video ); } elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) { ?> <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, 150, 150); ?>

<br /> <br /><?php } elseif ( 'gallery' === $post_format ) { et_gallery_images(); } } ?> <br /> <br /> <br /> <p style="color:#000000;"> <?php the_title(); ?> </p> <br /> <button class="button-0" >shop now</button>

        </a>

                    </div><!-- .post -->

            <?php endwhile; ?>
        <?php //endif; ?>

<?php if ( $wp_query->max_num_pages > 1 ) : ?> <div id="nav-below" class="navigation"> <?php next_posts_link( __( '<span class="meta-nav">รขโ€ ย</span> Older posts', 'twentyten' ) ); ?> </div><!-- #nav-below --> <?php endif; ?>

        </div><!-- #content -->

<?php get_footer(); ?>