• Hi, I’m struggling a little bit with converting a flat HTML site to WordPress – I would like to think I know the basics of WP but there are a couple of things bothering me –

    I have read and re-read the documentation about differences between Pages and Posts. However I am still not sure of the best way of doing what I want. Consider this example – the current site has a page describing an annual event which takes place, there are then separate pages for each of the occurrences of the annual event. So we have Page A which contain links to Page 2013, 2012, 2011 etc. Each of the 2013, 2012 etc pages (call them annual pages) contain a link back to Page A plus a link to the other annual pages.

    OK, so firstly I have created each of the annual pages as a Post. I had originally created Page A as a Page instead of a Post, and used the following plugin – https://www.ads-software.com/plugins/list-category-posts/ – to use a shortcode to output my links to the annual posts. The problem with that though was that once on an annual post although I can use a “Related Posts” widget to display the links to the other annual posts, there seemed to be no easy way to generate a link back to the Page A automatically. So I changed Page A to become a Post instead so I can hopefully use categories to generate this.

    Which would you say is the best practice? Thanks in advance for any advice.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Personally, I would have made A a Page with each of the annual events as Posts. Then I would have created a custom page template that created a a page of posts and applied it to Page A.

    Thread Starter tonysab

    (@tonysab)

    Hi, many thanks for your reply. I think that is pretty much what I had done originally (allbeit by using a plugin instead), but what I had a problem with then was I wanted to be able to link back easily to to Page A from the annual events pages – I couldn’t see an easy way to do this in the Related Posts widget. I suppose I could have manually added a link to the bottom of each post but I’d had preferred to have kept it consistently in the right column.

    I wanted to be able to link back easily to to Page A from the annual events pages

    Assuming you mean “annual events posts”, it should be possible to do this dynamically with a little pre-organisation. Will all of these Posts have in their own category? Or have their own tag? Or how do you feel about using custom fields?

    Thread Starter tonysab

    (@tonysab)

    Hi yes sorry I meant from the annual events posts. I have given each of the posts the same specific category.

    Well, that will make listing the posts a piece of cake. Will you only ever have one of these “pages of Posts”?

    Thread Starter tonysab

    (@tonysab)

    Hi yes that is correct. Although as mentioned I’ve got the listing of the posts working via a plugin, it’s the link back to page A I’m struggling to get my head around.

    You could use a custom field in each of the Posts called something like mybacklink. The value could be the name of the Page that you want to link back to. You could then add something like:

    // try to get the value of the field
    $my_page_name = get_post_meta( get_the_ID(), 'mybacklink', true );
    // do we have a page name & does such a page exist?
    if ( ! empty( $my_page_name ) && get_page_by_title( $my_page_name )) {
    	// It exists - so get the page
    	$my_linked_page = get_page_by_title( $my_page_name );
    	// output the link
    	echo '<a href="' . get_page_link( $my_linked_page->ID) . '">'. $my_page_name . '</a>';
    }

    to your theme’s single.php template file within the Loop.

    Thread Starter tonysab

    (@tonysab)

    Yes I can follow that, thanks for your help. I just got the feeling that what I was trying to do shouldn’t have been that difficult, that it was a common thing to do. Really that I had not been barking up the wrong tree. Thanks again.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Posts / Pages question’ is closed to new replies.