• 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>

    https://www.ads-software.com/extend/plugins/options-framework/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Devin Price

    (@downstairsdev)

    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 } ?>

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

    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: https://codex.www.ads-software.com/Conditional_Tags

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Select a page (if don't, not display) – Options Framework Plugin’ is closed to new replies.