WordPress PHP - Posts by Tag on Page

aspe_heat

Senior Member
Joined
Oct 7, 2010
Messages
810
Reaction score
595
Hey everyone!

I want to put the latest posts by a tag in my page.php file. I have that "Posts by Tag" plugin, but I just fail to configure it since I am not familiar with PHP. Preferably, I would need it to automatically read the tag from the page it is on, then show the latest posts using it.

Can anyone help me with this?
Thanks!
 
Try this and let me know if it works or not:

< ?php

posts_by_tag( 'aspeheat', array( 'number' => 10 );

?>

replace aspeheat with your tag, replace 10 with how many per page.

It should be by date by default
 
Try this and let me know if it works or not:

< ?php

posts_by_tag( 'aspeheat', array( 'number' => 10 );

?>

replace aspeheat with your tag, replace 10 with how many per page.

It should be by date by default

It won't work, gives this error:

Parse error: syntax error, unexpected '<' in /home/content/94/10862794/html/wp-content/themes/today/page.php on line 153

EDIT: I tried with removing < ?php and some other parts of the code, but still won't work.
 
Last edited:
it might be because of < ?php should be <?php remove the white space

not sure that makes a difference but its the only reason I can see for your browser to see a <
 
Yes, tahworld meant to put "<?php" instead of "< ?php".

If it's still not working though, maybe try making sure there's not already an opened <?php tag up above in your coding. I would think that if you misspelled "< ?php" that it would simply output that onto your page instead of an error message. But when <?php is already open, I don't think it's going to recognize a second "<?php" or anything starting with a "<" for that matter.
 
Yes, tahworld meant to put "<?php" instead of "< ?php".

If it's still not working though, maybe try making sure there's not already an opened <?php tag up above in your coding. I would think that if you misspelled "< ?php" that it would simply output that onto your page instead of an error message. But when <?php is already open, I don't think it's going to recognize a second "<?php" or anything starting with a "<" for that matter.

Yes, there's the tag at the beginning of the page. I tried removing it from this, but then I get the following error:

Parse error: syntax error, unexpected ';' in /home/content/94/10862794/html/wp-content/themes/today/page.php on line 153
 
Back
Top