Results 1 to 7 of 7

Thread: Shortcodes not displaying

  1. #1
    sf23103 is offline Hello World
    Join Date
    Jul 2011
    Posts
    5

    Default Shortcodes not displaying

    Hello! I am having problems with shortcodes... they are not working (they display the actual shortcode). If I replace
    Code:
    <?php echo $ps->post_content;/*the_content();*/ ?>
    with
    Code:
    <?php the_content();?>
    the shortcodes work, but then the same content displays for every post!

    Any ideas? The following is my single.php file


    Code:
    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    
    get_header(); ?>
    
            <?php /*?><div id="container">
                <div id="content" role="main"><?php */?>
                <div id="interior_large">
                    <img src="<?php echo get_bloginfo( 'template_url' ); ?>/images/BOXES_SECONDARY_TOP.jpg" />
                    <div id="boxes_for_pages">
                        <div id="boxes_for_pages_left">
    
                            <?php get_sidebar(); ?>
                        </div>
                        <div id="boxes_for_pages_right">
                            <?php
                            /* Run the loop to output the post.
                             * If you want to overload this in a child theme then include a file
                             * called loop-single.php and that will be used instead.
                             */
                            //get_template_part( 'loop', 'single' );
    
                            $posts = explode('/',$_SERVER['REQUEST_URI'],-1);
    
                            function get_post_by_slug($post_name) {
    
                                global $wpdb;
    
                                $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='post'", $post_name ));
    
                                if( $post ) {
                                    return get_post($post);
                                }
    
                                return null;
                            }
    
                            if($posts[3]!='')
                            {
    
                                $ps = get_post_by_slug($posts[3]);
    
                            }
                            else
                            {
    
                                $ps = get_post_by_slug($posts[2]);
    
                            }
                            /*echo "<pre>";print_r($ps);echo "</pre>";*/
                            //query_posts($ps);
    
                            ?>
    
                        <div id="post-<?php echo $ps->ID; ?>" <?php post_class(); ?>>
                        <div id="boxes_for_pages_right_text"><?php echo $ps->post_title; ?></div>
                        <div id="boxes_for_pages_right_text_sub">
                            <div class="entry-meta">
                                <?php /*twentyten_posted_on();*/ ?>
                            </div><!-- .entry-meta -->
    
                            <div class="entry-content">
    
                                <?php echo $ps->post_content;/*the_content();*/ ?>
                                <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                            </div><!-- .entry-content -->
    
        <?php if ( get_the_author_meta( 'description' ) ) : // If a user has filled out their description, show a bio on their entries  ?>
                            <div id="entry-author-info">
                                <div id="author-avatar">
                                    <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyten_author_bio_avatar_size', 60 ) ); ?>
                                </div><!-- #author-avatar -->
                                <div id="author-description">
                                    <!--<h2>--><?php /*printf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ); ?></h2>
                                    <?php the_author_meta( 'description' );*/ ?>
                                    <!--<div id="author-link">
                                        <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
                                            <?php printf( __( 'View all posts by %s <span class="meta-nav">→</span>', 'twentyten' ), get_the_author() ); ?>
                                        </a>
                                    </div>--><!-- #author-link    -->
                                </div><!-- #author-description -->
                            </div><!-- #entry-author-info -->
        <?php endif; ?>
    
                            <div class="entry-utility">
                                <?php /*twentyten_posted_in();*/ ?>
                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                            </div><!-- .entry-utility -->
                        </div>
                    </div>
    
                        </div>
                    </div>
                    <img src="<?php echo get_bloginfo( 'template_url' ); ?>/images/BOXES_SECONDARY_BTTM.jpg" />
                </div>
                <?php /*?></div><!-- #content -->
            </div><!-- #container --><?php */?>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  2. #2
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    First to run shortcode you call do_shortcode(text);
    Second:
    What is that you want to accomplish that the default TwentyTen don't handle?
    From what I can tell you are just replacing functional code with bad code. Combining one TwentyTen file with another TwentyTen file and then replacing the code with bad code.
    Look at TwentyTen/loop-single.php to learn how to do it properly.
    Also you should check out how to do child themes. If you read loop-single.php it says if you want to replace this include it in a child theme.
    PS
    Don't use get_bloginfo( 'template_url' )
    Learn how these functions work
    get_stylesheet_directory_uri()
    admin_url()
    site_url()
    plugins_url()
    includes_url()
    content_url()
    http://codex.wordpress.org/Function_...ated_Functions

  3. #3
    sf23103 is offline Hello World
    Join Date
    Jul 2011
    Posts
    5

    Default

    Thank you so much for your reply.

    Basically what happened is that I created a website template for a client and was then asked to convert it to a wordpress theme. Not knowing much about php and not having any time to learn wordpress I hired a programmer to build a theme out of my existing template.

    The site has a home page with editable content and then sub pages. There are several categories for content. Depending on which category you are in, the category name displays on the left side and all of the posts in that category display below by name. When you click on a topic, the single post displays on the right. The theme is basically using wordpress a a CMS.

    So based on what you are saying, it sounds like the programmer got it to work for me, but didn't go about it the right way, leaving me with this bug.

    Any Suggestions? ;-)

    Quote Originally Posted by andreasnrb View Post
    First to run shortcode you call do_shortcode(text);
    Second:
    What is that you want to accomplish that the default TwentyTen don't handle?
    From what I can tell you are just replacing functional code with bad code. Combining one TwentyTen file with another TwentyTen file and then replacing the code with bad code.
    Look at TwentyTen/loop-single.php to learn how to do it properly.
    Also you should check out how to do child themes. If you read loop-single.php it says if you want to replace this include it in a child theme.
    PS
    Don't use get_bloginfo( 'template_url' )
    Learn how these functions work
    get_stylesheet_directory_uri()
    admin_url()
    site_url()
    plugins_url()
    includes_url()
    content_url()
    http://codex.wordpress.org/Function_...ated_Functions

  4. #4
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    Ok well the programmer is not very knowledgeable of WordPress then.
    Anyway to get shortcode working do this
    echo do_shortcode($ps->post_content);

  5. #5
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    Just had a quick overall think I converted correctly.
    Code:
    <?php	/**	 * The Template for displaying all single posts.
    	 *
    	 * @package WordPress
    	 * @subpackage Twenty_Ten
    	 * @since Twenty Ten 1.0
    	 */
    
    
    	get_header();?>
    
    
    <div id="interior_large">
    	<img src="<?php	echo get_bloginfo('template_url');?>/images/BOXES_SECONDARY_TOP.jpg" />
    	<div id="boxes_for_pages">
    		<div id="boxes_for_pages_left">
    			<?php	get_sidebar();?>
    		</div>
    		<div id="boxes_for_pages_right">
    			<?php if ( have_posts() ) while ( have_posts() ) : the_post();
    			?>
    			<div id="post-<?php	the_ID();?>" <?php	post_class();?>
    				>
    				<div id="boxes_for_pages_right_text">
    					<h1 class="entry-title">
    					<?php	the_title();?>
    					</h1>
    				</div>
    				<div id="boxes_for_pages_right_text_sub">
    					<div class="entry-meta">
    					</div><!-- .entry-meta -->
    
    
    					<div class="entry-content">
    						<?php	the_content();?>
    						<?php	wp_link_pages( array('before' => '<div class="page-link">' . __('Pages:', 'twentyten'), 'after' => '</div>'));?>
    					</div><!-- .entry-content -->
    
    
    					<?php if ( get_the_author_meta( 'description' ) ) : // If a user has filled out their description, show a bio on their entries
    					?>
    					<div id="entry-author-info">
    						<div id="author-avatar">
    							<?php	echo get_avatar(get_the_author_meta('user_email'), apply_filters('twentyten_author_bio_avatar_size', 60));?>
    						</div><!-- #author-avatar -->
    					</div><!-- #entry-author-info -->
    					<?php	endif;?>
    
    
    					<div class="entry-utility">
    						<?php	edit_post_link(__('Edit', 'twentyten'), '<span class="edit-link">', '</span>');?>
    					</div><!-- .entry-utility -->
    				</div><!-- #post-## -->
    				<?php endwhile; // end of the loop.?>
    			</div>
    <img src="<?php	echo get_bloginfo('template_url');?>/images/BOXES_SECONDARY_BTTM.jpg" />			
    		</div>
    	</div>
    </div>       	
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  6. #6
    sf23103 is offline Hello World
    Join Date
    Jul 2011
    Posts
    5

    Default

    Wow andreasnrb, thanks so much for taking the time to do that.

    I pasted the code and adjusted a missing div to make it look right, but now when I click on a specific post, all of the other posts display under it, instead of showing one post at a time. Isn't that the point of the single.php file? argh! ;-)

  7. #7
    sf23103 is offline Hello World
    Join Date
    Jul 2011
    Posts
    5

    Default

    So using my original code, I replaced <?php echo $ps->post_content;/*the_content();*/ ?> with <?php echo do_shortcode($ps->post_content); ?> and it seems to be working. Keeping my fingers crossed.

    I think I'll come here next time to seek out someone to help instead of using who I did!! ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •