Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Server-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2008, 02:22 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 659
Default string inside a function?

I'm trying to manipulate WordPress's wp_list_pages function for my dropdown menu plugin.

The following code, will generate a complete list of pages in your WordPress install, minus page number 262
PHP Code:
<ul>
    <?php wp_list_pages('exclude=262' ); ?>
</ul>
I want to allow users of my plugin to remove pages from their list via the admin panel. To do this, I first considered creating a string which contains the page number they want to exclude (eg: 262) and inserting that into the function like so:
PHP Code:
<ul>
    <?php
    wp_list_pages
('exclude=$whatever' ); ?>
</ul>
However when I tried this, it simply ignored the string.

Any ideas on how to get around this problem? It is a feature many of my plugins users would like but I haven't yet figured out how to implement it.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-14-2008, 07:21 AM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 298
Send a message via MSN to BigAlReturns
Default

Well I had a look at the WP documentation here, and you seem to be doing it right. Are you sure the variable contains just a number, and that it corresponds to a page?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-14-2008, 09:57 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 659
Default

The documentation doesn't say anything about using strings within the function though.

In case you are confused about which part of the code I'm talking about, I'll highlight it below:

<ul>
<?php
wp_list_pages('exclude=$whatever' ); ?>
</ul>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-14-2008, 12:36 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 298
Send a message via MSN to BigAlReturns
Default

Quote:
Originally Posted by ryanhellyer View Post
<ul>
<?php
wp_list_pages('exclude=$whatever' ); ?>
</ul>
Ah, well that would be a variable not a string
I think the problem is that you're using single quotes instead of double quotes - with singles, variables inside are not replaced with their value. You can either change to double quotes, or if this isn't convenient in the cotext of the surrounding code, just use concatenation like below:

wp_list_pages('exclude=' . $whatever);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-20-2008, 01:22 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 659
Default

Quote:
Originally Posted by BigAlReturns View Post
... you're using single quotes instead of double quotes - with singles, variables inside are not replaced with their value.

BINGO!

That did the trick A new version of my dropdown plugin will be released shortly with the option to exclude certain pages and categories from the dropdown
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-20-2008, 01:37 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 659
Default

BigAlReturns - I'd like to add a credit to you in my plugin. What URL should I link to? And would you prefer your real name or just "BigAlReturns"?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-20-2008, 04:13 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 659
Default

And my code is done

BigAl, I've added a credit to you in the plugin itself and on the beta page of my plugin ... WordPress Dropdown Menu Plugin Version 1.9.0 Beta | Ryan Hellyer’s Website

Once it comes out of beta, you get a link on the main plugin page and in the WordPress plugins repository.

I've used your blog for the link and your internet handle as your name at this stage, but I can change that later if you prefer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.