WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to build a gallery page that is responsive to the post ID. After discussing ideas with a friend who is far more knowledgeable in WP he suggested I use post ID in my arguments that is passed through the shortcode. I studied up on the gallery shortcode in the codex and noticed this intval($post->post_parent) so I placed that into my code for the gallery id and my page still displays every image that is in my media library, not the the images in the gallery I created. I want to keep my photoshop works separate from my astrophotography work on my portfolio.

here is my website link to the gallery (the gallery I constructed consists ONLY of the space photographs, the other images are photoshop.


Here is the code from my gallery.php page:

    //Calling arguments for gallery. This is the place to change the information for which gallery is to be displayed
    $gallery_shortcode = '[gallery id="' . intval($post->post_parent) . '" columns="3" order="ASC" orderby="ID" gallery itemtag="div" icontag="span" captiontag="p" gallery size="medium"]';

<?php get_header(); ?>

<h1 class="contact-title">Astrophotography Gallery</h1> <!-- To be changed so it will display the post name instead -->

<div class="row">
<?php echo do_shortcode($gallery_shortcode); ?>

<?php get_footer(); ?>

Also is there a way to override or otherwise disable the pre-generated css that wp inserts for the galleries? This is what is added when the page is rendered:

<style type='text/css'>
        #gallery-1 {
            margin: auto;
        #gallery-1 .gallery-item {
            float: left;
            margin-top: 10px;
            text-align: center;
            width: 33%;
        #gallery-1 img {
            border: 2px solid #cfcfcf;
        #gallery-1 .gallery-caption {
            margin-left: 0;
        /* see gallery_shortcode() in wp-includes/media.php */

Finally if this ins't possible, I guess my next best bet would bet the nextgen gallery plugin?

share|improve this question
as i can see "galleryid-0" in the page you linked, my guess is that intval($post->post_parent) isn't working as expected, you can do a var_dump($post) to see what you have in $post – Puggan Se Aug 14 '13 at 5:49
what I get back is a really long string, too long for here. You can see it though on the page. It is saying object(WP_Post)#115 (25) at the beginning. – NathanJ2012 Aug 14 '13 at 6:13
dose it have a "post_parent"-id? dose it have the id you want but named to somthing else? – Puggan Se Aug 14 '13 at 8:41
I need it to be dynamic as I am not saving the database when I move it to my main domain. If I use the specific post it won't work when I move it over. – NathanJ2012 Aug 14 '13 at 11:34
dynamic related to what? related to the "post_parent"? as the "post_parent" is 0 ["post_parent"]=>int(0), that's properly not the id you was looking for, maybe its ["ID"]=> int(147) that you looking for, in that case use $post->ID – Puggan Se Aug 14 '13 at 11:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.