0

Hi everyone,

I'm sure this is a simple fix but it may take a minute to understand what I'm trying to achieve.

Here is my code, as you can see it's for a shortcode:

function verticalnav_func( $atts ) {
    extract( shortcode_atts( array(
        'category' => '0',
    ), $atts ) );
?>

<div id="TabbedPanels2" class="VTabbedPanels">

  <ul class="TabbedPanelsTabGroup">

  <!-- Repeat for each content -->

    <?php
    $args=array(
      'showposts' => 8,
      'category__in' => 6,
      'orderby'         => 'post_date',
      'order'         => 'ASC'
    );
    $posts=get_posts($args);
      if ($posts) {
        foreach($posts as $post) {
          setup_postdata($post); ?>
     <li class="TabbedPanelsTab" tabindex="0"><?php the_title(); ?></li>
          <?php
        } // foreach($posts
      } // if ($posts

?>

  <!-- End repeat -->

  </ul>

  <div class="TabbedPanelsContentGroup">

  <!-- Repeat for each content -->

    <?php
    $args=array(
      'showposts' => 8,
      'category__in' => 6,
      'orderby'         => 'post_date',
      'order'         => 'ASC',
      'caller_get_posts'=>1
    );
    $posts=get_posts($args);
      if ($posts) {
        foreach($posts as $post) {
          setup_postdata($post); ?>
    <div class="TabbedPanelsContent"><?php the_content(); ?></div>
          <?php
        } // foreach($posts
      } // if ($posts

?>

  <!-- End repeat -->

  </div>
<div style="clear: both;"></div>
</div>

<?php
}
add_shortcode( 'vertical-navigation', 'verticalnav_func' );
?>

The shortcode [vertical-navigation] is placed within a post called "NVQ's", and when called is meant to display a vertical navigation list of posts within category 6.

HOWEVER,

It is getting the_content correctly from each of the posts within category 6, but when it attempts to get_title it's just returning "NVQ's" which is the title of the current page.

Any thoughts?

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Designer_101
1

Do any of the other wordpress functions work?

You might try using
<?php echo get_the_title(); ?> instead.

Votes + Comments
You were right! :)
0

Do any of the other wordpress functions work?

Thanks for your reply :)

I believe you'd have to use an ID with that function, and I have no idea how to include that in this context.

The confusing this is that the_content is working fine. In the vertical menu there are 5 tabs (as there are 5 posts in category 6), each has "NVQ's" as the tab's title, but the content that goes with it is appropriate to each post.

**For some reason, the_title is returning the title of the post in which this shortcode is placed. **

So confused.

Edited by Designer_101

1

Since you have setup_postdata($post); the ID should be optional. If you did want to specify the id use $post->ID

Using a shortcode you should return the html and not echo it out.

**For some reason, the_title is returning the title of the post in which this shortcode is placed. **

Try adding the ID in then. <?php echo get_the_title($post->ID); ?> I think that would add extra queries to the database though.

Votes + Comments
Worked a charm!
0

Try adding the ID in then. <?php echo get_the_title($post->ID); ?> I think that would add extra queries to the database though.

Thankyou so much! And that's to both of you as I know kreitje also tried to tell me this.

Works a charm, which is odd because I swear I tried this earlier.

Oh well, thanks again! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.