0
votes

So i'm quite a beginner, trying to make a custom theme. In a page i want to have a gallery. Uploaded images, made a gallery all fine.

When I view the page it outputs only the shortcode:

[gallery orderby="post_date"]

my page.php file basically has:

<?php $content = get_page( $page_id ) ?>

<div id='content' class='shadow'>
    <div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>

<?php echo $content->post_content ?>
    </div>
</div>


<?php get_sidebar(); ?>

<?php get_footer(); ?>

I really don't understand how to get this to show correctly, any pointers would be greatly appreciated. Cheers, Matt

1

1 Answers

1
votes

get_page returns the raw page data. There are a few ways to do what you want:

BAD WAY:

<?php $content = get_page( $page_id ) ?>

<div id='content' class='shadow'>
    <div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>

<?php echo do_shortcode($content->post_content); ?>
    </div>
</div>


<?php get_sidebar(); ?>

<?php get_footer(); ?>

do_shortcode() renders all registered shortcode that's found within a given string. In this case, your page's content will have all shortcode rendered before being written to the document. I say this is the "bad" way, only because it doesn't follow the usual Wordpress format. Which leads us to the:

BETTER WAY:

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>

<div id='content' class='shadow'>
    <div id='innercontent'>
<!---page title-->
<h1><?php the_title(); ?></h1><br>
<?php the_content(); ?>
    </div>
</div>
<?php endwhile;endif; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

This is what's called "The Loop". It is pretty much the standard for all Wordpress Themes in retrieving all Post or Page Data, as well as running queries against the database.

I would suggest getting to know it, as well as running Wordpress queries to modify the loop using WP Query. This is getting into a more complex area of Wordpress, but it will help you in the longrun with figuring out how to gather up all of the posts and pages you want to retrieve in your theme that aren't provided by Wordpress' globals.

Good luck.