Forums

code clean-up: querying a specific post (6 posts)

  1. Pete
    Member
    Posted 10 months ago #

    I was wondering if someone could be so kind as to clean this up for me so that I don't have to keep on defining the post, but instead define it once at the start and just use the normal title, content and featured image tags etc.

    Thanks heaps.

    <h2><?php $post_id = of_get_option('tabber_post1', 'no entry' ); $queried_post = get_post($post_id); echo $queried_post->post_title; ?></h2>
    
    <h1><a href="<?php echo get_permalink($post_id = of_get_option('tabber_post1', 'no entry' )); ?>" rel="bookmark"><?php $post_id = of_get_option('tabber_post1', 'no entry' ); $queried_post = get_post($post_id); echo $queried_post->post_title; ?></a></h1>		
    
    <?php $post_id = of_get_option('tabber_post1', 'no entry' ); $queried_post = get_post($post_id); $content = $queried_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?>
  2. birgire
    Member
    Posted 10 months ago #

    Pete: You could try this

    <?php
    // only get post and option once:
    $post_id = of_get_option('tabber_post1', 'no entry' );
    $queried_post = get_post($post_id);
    ?>
    
    <h2>
    	<?php echo $queried_post->post_title; ?>
    </h2>
    
    <h1>
    	<a href="<?php echo get_permalink($post_id); ?>" rel="bookmark">
    		<?php echo $queried_post->post_title; ?>
    	</a>
    </h1>		
    
    <?php
    $content = $queried_post->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    ?>
  3. Pete
    Member
    Posted 10 months ago #

    Thanks, close but not quite there :)

    check out my home page (shockwave-electrical.com).

    I'm using your code for the first post in the tabber' section, so the tab is gone and it's post goes above the content of the other tabs... make sense?

  4. birgire
    Member
    Posted 10 months ago #

    First, the line

    $content = str_replace(']]>', ']]>', $content);

    is not doing anything, you could get rid of it.

  5. birgire
    Member
    Posted 10 months ago #

    Mabye you are missing some html-tags?

    For example:

    <div class="tabbertab  " title="">
    
    <?php
    // only get post and option once:
    $post_id = of_get_option('tabber_post1', 'no entry' );
    $queried_post = get_post($post_id);
    ?>
    
    <h2>
    	<?php echo $queried_post->post_title; ?>
    </h2>
    
    <h1>
    	<a href="<?php echo get_permalink($post_id); ?>" rel="bookmark">
    		<?php echo $queried_post->post_title; ?>
    	</a>
    </h1>		
    
    <p>
    <?php
    $content = $queried_post->post_content;
    $content = apply_filters('the_content', $content);
    echo $content;
    ?>
    </p>
    
    <div class="clear"></div>				
    
    </div>
  6. birgire
    Member
    Posted 10 months ago #

    edit: sorry for the comment duplication

    (removed this duplicated comment)

Reply

You must log in to post.

About this Topic

Tags