Jump to content

WP Coding Problem


SkyRanger

Recommended Posts

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'); ?>
Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/#findComment-1479405
Share on other sites

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'); ?>
Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/#findComment-1479411
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/#findComment-1479433
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/#findComment-1479473
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/288471-wp-coding-problem/#findComment-1479485
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.