1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress PHP - Posts by Tag on Page

Discussion in 'Blogging' started by aspe_heat, Jan 22, 2014.

  1. aspe_heat

    aspe_heat Power Member

    Joined:
    Oct 7, 2010
    Messages:
    799
    Likes Received:
    595
    Gender:
    Male
    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!
     
  2. tahworld

    tahworld Regular Member

    Joined:
    Aug 16, 2013
    Messages:
    457
    Likes Received:
    393
    Location:
    ✔✔✔✔✔✔✔
    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
     
    • Thanks Thanks x 1
  3. aspe_heat

    aspe_heat Power Member

    Joined:
    Oct 7, 2010
    Messages:
    799
    Likes Received:
    595
    Gender:
    Male
    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: Jan 22, 2014
  4. tdivan

    tdivan Newbie

    Joined:
    Aug 12, 2013
    Messages:
    46
    Likes Received:
    16
    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 <
     
  5. TimothyEyton

    TimothyEyton Junior Member

    Joined:
    Dec 30, 2013
    Messages:
    127
    Likes Received:
    62
    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.
     
  6. aspe_heat

    aspe_heat Power Member

    Joined:
    Oct 7, 2010
    Messages:
    799
    Likes Received:
    595
    Gender:
    Male
    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
     
  7. gsy159

    gsy159 Power Member

    Joined:
    Apr 29, 2011
    Messages:
    655
    Likes Received:
    158
    <?php

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

    ?>
     
    • Thanks Thanks x 1
  8. aspe_heat

    aspe_heat Power Member

    Joined:
    Oct 7, 2010
    Messages:
    799
    Likes Received:
    595
    Gender:
    Male
    I love you, man! It finally works!
     
    Last edited: Jan 23, 2014