Forums

It can't be *that* hard! want to link direct to latest post in category (2 posts)

  1. edzillion
    Member
    Posted 3 years ago #

    Hi

    All I want to do is have a link on my webpage called 'latest research update' that links to the latest post tagged 'research_update'.

    I have tried the following:

    1. Writing an sql command to get the latest posts url (this was harder than I thought and I abandoned it)

    2. Parsing the feedburner feed to get the url of the top story (this worked to some extent but means that I have to turn off click-through tracking unless I want all clicks of this link to be recorded through feedburner, also it seems unduly slow)

    3. Now trying to parse the default wordpress feed. If I put the feed url direct into the browser:

    http://blog.domain.tld/category/research_update/feed

    I get the contents of the feed (as displayed in the browser), but if I try to parse the feed, using php like so:

    $fp = fopen( "http://blog.domain.tld/category/research_update/feed/", "r" )
    or die( "Cannot read RSS data file." );

    This gives the error "Cannot read RSS data file."

    What is the easy way to do this? Can you point me in the right direction already?

    Thanks
    Ed

  2. kwbridge
    Member
    Posted 3 years ago #

    You could do something like this

    Do you know how to make a page template? It's about halfway down the page http://codex.wordpress.org/Pages

    Make a new template and call it whatever you want. You can use the same code that's on the index.php template. Right before the while code add

    <?php query_posts('category_name=wordpress&showposts=1'); ?>

    So it looks like

    <?php query_posts('category_name=wordpress&showposts=1'); ?> (put whatever the name of the category is in place of wordpress)

    <?php while (have_posts()) : the_post(); ?>

    So, this template will only show the last post in the specified category.

    Now write a new page called. Don't put anything in the area where we usually write stuff. Just give it a title. Scroll down and there is a section called Templates - in 2.7 it's on the right under Attributes. Select the template you just made. Once it is saved you will have the permalink under the title. You can then use that permalink to link to this page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags