0

I'm using WordPress. I appreciate being shown the code, but this is one I am interested in straight out learning how to do myself too - so if you know where I can find a tutorial or can give me information I'd appreciate it!

I'm calling posts and want to include a PHP code within a PHP code, this is for a theme options panel.

<?php
query_posts('cat=-51&posts_per_page=3&paged='.$paged); 
if (have_posts()) :
?>

Where the 51 is I want to put:

<?php echo get_option('to_postc_home'); ?>

Where the 3 is I want to put:

<?php echo get_option('to_posti_home'); ?>

6 Answers 6

3

If I'm interpreting right, this is what you need, use the concatenation operator . to use those functions in place of plain text ex: 'this is text' versus 'this '.get_option('stuff').' text'

<?php
    query_posts('cat='.get_option('to_postc_home').'&posts_per_page='.get_option('to_posti_home').'&paged='.$paged); 
    if (have_posts()) :
?>
Sign up to request clarification or add additional context in comments.

Comments

0

To include a php file from another file you use the include function

Comments

0

You can use it whereever you want

<?php
query_posts('cat=-51&posts_per_page=3&paged='.$paged); 
if (have_posts()) :
?>
hello world
<?php echo get_option('to_postc_home'); 
endif;

Comments

0
<?php
  $a = get_option('to_postc_home');
  $b = get_option('to_posti_home');

  query_posts("cat={$a}&posts_per_page={$b}&paged={$paged}");

  if (have_posts())
?>

Comments

0

That is called string concatenation, and you are already using that on the first line of your code, when you concatenate the literal string 'cat=-51&posts_per_page=3&paged=' with the variable $paged. In PHP, the . operator does that.

So, in your code, you can do this:

<?php
query_posts('cat=-' . get_option('to_postc_home') . '&posts_per_page=' . get_option('to_posti_home') . '&paged='.$paged); 
?>

This will inject the output of the function calls at the places you indicated.

Comments

0
<?php
$cat = get_option('to_postc_home');
$per_page = get_option('to_posti_home');

query_posts("cat=${cat}&posts_per_page=${per_page}&paged=".$paged);
if (have_posts())
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.