Support » Fixing WordPress » A PHP and loop question

  • Hopefully someone knows how to do this. On my post pages, I want the title and contents of all posts with the same tag to be generated below the single post content. I can do this by using a query with the tag name as a parameter. However I need a way to generate the tag related to each specific post and then insert it into the query. Does anyone have any ideas on how I can do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You would have to edit single.php of your theme or create a Child Theme.

    Are you sure you want the full contents of all posts with the same tag, etc.? Could result in very long pages. You might be better off with a Related Posts plugin.

    Thread Starter mignonnemax

    (@mignonnemax)

    Thanks for the quick input, Jonas
    I’m designing a custom theme for my client, and she wants the entire contents of the related posts displayed. The plug-ins I’ve looked at only display the titles with links. I can get what I want with the code below (somewhat abbreviated) but the added challenge is that the tag name (in this case, “memory of magnolia” would need to change to reflect the post being displayed.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    There is probably a better way to do this than using tags to associate posts. If you have any ideas, I’d appreciate it.

    Mignonne

    You could probably easily hack one of those plugins to show more than just the title. Another way would probably be multiple loop code.

    Thread Starter mignonnemax

    (@mignonnemax)

    Boy, I’ve sure tried to hack the plugin codes–and wasted hours (days!) trying to get it to work. I was using Efficient Related Posts, and emailed the authors for advice (their support forum is closed) but haven’t heard back. I thought I knew a little bit about PHP but this one is stumping me!

    Two loops??:

    Loop 1 is the single post…

    Once that is chosen we decide what tag to use for:

    Loop 2 is posts of that tag sorted by date (?) and limited to ‘x’ recent posts

    Thread Starter mignonnemax

    (@mignonnemax)

    Hi SwansonPhotos

    That sounds interesting–
    could you give me an example of what that would look like in code?

    Thanks!

    The link has several suggestions within the posts…I am not a PHP *pert…so I will defer to their advise, read the posts!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘A PHP and loop question’ is closed to new replies.