WordPress.org

Ready to get started?Download WordPress

Forums

Options Framework
Select a page (if don't, not display) - Options Framework Plugin (4 posts)

  1. brightweb1
    Member
    Posted 1 year ago #

    Hello.

    I found your framework a few days ago and am loving it!

    But I have little doubt...

    If I select a page, the system displays the contents. But if I don't choose any page, it shows the default loop (with posts). Is there a way to set up to display none?

    The code:

    <div>
       <?php $recent = new WP_Query('page_id='.of_get_option('test')); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_excerpt(); ?>
       <?php endwhile; ?>
       <a href="<?php the_permalink() ?>" rel="bookmark">Learn More</a>
    </div>

    http://wordpress.org/extend/plugins/options-framework/

  2. Devin Price
    Member
    Plugin Author

    Posted 1 year ago #

    Wrap your whole query inside of_get_option('test').

    E.g.:

    <?php if ( of_get_option('test', false ) ) { ?>
    <div>
       <?php $recent = new WP_Query('page_id='.of_get_option('test')); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_excerpt(); ?>
       <?php endwhile; ?>
       <a href="<?php the_permalink() ?>" rel="bookmark">Learn More</a>
    </div>
    <?php } ?>
  3. Pete
    Member
    Posted 1 year ago #

    How could you edit this if you wanted to display pages OR posts?

  4. DigiDocs
    Member
    Posted 1 year ago #

    You would use an else if statement:

    <?php
    	$opid1 = of_get_option('myoptionsid1');
    	$opid2 = of_get_option('myoptionsid2'); /* And so on to call more optionfields*/
    
    ?>
    <?php
    if (empty($opid1)) { ?>
      /* Choise what to do if field $opid1 IS empty */
    <?php echo ''; ?> /* Displays whatever is between the '', in this case nothing */
    
    <?php } else if { ?>
    /* First choise what to do if field $opid1 NOT empty */
    <a href="<?php echo ($opid1); ?>"> /* myoptionsid1 are in this case an URL to wherever i want to link*/
    <img src="<?php echo ($opid2); ?>" /> /* myoptionsid2 are in this case an URL to an image*/
    </a>
    
    <?php } else if { ?>
    /* Second choise what to do if field $opid1 NOT empty. And so on... */
    
    <?php } else { ?>
    /* Last choise what to do if field $opid1 NOT empty */
    
    <?php };
    ?>

    For more if else statements: http://codex.wordpress.org/Conditional_Tags

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic