SkyRanger Posted May 14, 2014 Share Posted May 14, 2014 Not sure if or how I can do this properly without killing my page: <?php $catquery = new WP_Query( 'cat=16&posts_per_page=1 ); while($catquery->have_posts()) : $catquery->the_post(); $ourspecials = " <ul> <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <ul><li><?php the_content(); ?></li> </ul> </li> </ul>"; ?> <?php if(function_exists('stbHighlightText')) stbHighlightText($ourspecials, 'warning'); ?> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 14, 2014 Share Posted May 14, 2014 (edited) Um, what? Is this a question? A demonstration? A riddle? All I see is some badly broken PHP code which looks as if you've randomly pressed some keys. No parser will ever understand this. If you're trying to fix the code, it's probably best to start over, this time using actual PHP syntax. And you should start thinking about security. Raw PHP values inside HTML markup are a sure way of creating cross-site scripting vulnerabilities. Edited May 14, 2014 by Jacques1 Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 14, 2014 Author Share Posted May 14, 2014 (edited) Um, thanks Jacques for your delightful answer, guess I should have explained a little better I am trying to echo this: <?php $catquery = new WP_Query( 'cat=16&posts_per_page=1 ); while($catquery->have_posts()) : $catquery->the_post(); ?> <ul> <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <ul><li><?php the_content(); ?></li> </ul> </li> </ul> In here <?php if(function_exists('stbHighlightText')) stbHighlightText(echo output here, 'warning'); ?> Edited May 14, 2014 by SkyRanger Quote Link to comment Share on other sites More sharing options...
trq Posted May 14, 2014 Share Posted May 14, 2014 Have another go. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 14, 2014 Author Share Posted May 14, 2014 Reading over my code for the 10th time, I finally think I found the problem. It is 1 am here going to try and fix in morning. Will post what my results are. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 14, 2014 Share Posted May 14, 2014 Well, I don't think trial-and-error will help. Since you're obviously new to PHP, you should slow down and do this step by step. Writing down 10 lines of code in one go only to find out that everything broken isn't very useful, because now you're stuck and need others to untangle the problem. Instead, grab a proper IDE like Netbeans and write one statement. Just one. The IDE will analyze it and tell you whether it's syntactically sound. If the statement is valid, you can go on with the next one. Otherwise you fix this one broken statement. From time to time, you should also check if the code is actually doing the right thing. The point is that you only have to debug one statement at a time. This is much easier than having to deal with 10 lines of broken code. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 14, 2014 Share Posted May 14, 2014 If you can provide any actual errors shown, that would be helpful. WP has no "environment" like most modern PHP frameworks offer. So to see the errors, you must set WP_DEBUG to TRUE in wp-config.php. Just looking at your code, there are a couple things wrong. First, you're not ending your while loop. Secondly, you will probably need to use output buffering to capture the output generated, then insert it into your function. Look at the PHP manual for ob_start, and then go from there. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted May 14, 2014 Share Posted May 14, 2014 Every time I look at WordPress code, I have a mini-stroke. So much crap under the hood, with more crap bolted on top in the form of plugins. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted May 14, 2014 Share Posted May 14, 2014 (edited) Every time I look at WordPress code, I have a mini-stroke. So much crap under the hood, with more crap bolted on top in the form of plugins. I always tell people that WordPress is a great example of how not to code. It's the definition of spaghetti code. Makes CodeIgniter look like a golden nugget, LOL. Edited May 14, 2014 by sKunKbad Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted May 14, 2014 Solution Share Posted May 14, 2014 Haven't you wondered why, in the code in first post, the code in the while() statement is the same colour as the string in your WP_Query call? Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 14, 2014 Author Share Posted May 14, 2014 scrapped Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.