• Resolved jthomasc

    (@jthomasc)


    I have a site that has it’s own content management system.
    I am using data in that system to build user pages.

    The design calls for the blog to be inline in one of these pages for each user. I am thinking I would use the author var to display that users posts on each of their respective pages.

    So an example of an initial link to a user blog is https://www.mysite.com/blog/?author=1&user=2 where the author pulls from the wordpress DB and the user from my CMS, but the links that flow within that off the titles and the add comment and to other posts I need to append the &user=2 so that the correct information for that user appears on the page.

    Now I have had success using php to append that to the links I have access to in the template pages but the design includes taking advantage of the get_calendar() aspect of wordpress.

    I am wondering if it possible to get at the links generated in that so I can append the user id to maintain the CMS aspect of the site through those links.

    Also I am not the most experienced php programmer, so go easy on me.

    Thanks for any help you can offer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • It would create a tiny bit of overhead to process, but one method is to use PHP’s output buffering to capture the output of the WordPress function, then use a little pattern matching to attach your query string addition to any url.

    The following *should* work, though it might be painful…:)

    <?php
    ob_start();
    get_calendar();
    $user_calendar = ob_get_contents();
    ob_end_clean();

    $user_calendar = preg_replace('/(<a href=".*)"/U', '\\1' . "&user=$USERID" . '"', $user_calendar);

    echo $user_calendar;
    ?>

    In summary the code 1. puts the output of get_calendar() in $user_calendar, 2. uses preg_replace to add &user=$USERID to each url, and 3. displays the calendar. $USERID would be replaced with what you’re using to assign the ‘user’ query value.

    Thread Starter jthomasc

    (@jthomasc)

    Thank you so much, that worked like a charm.
    Mark this question resolved.

    Very much appreciated.

    J.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Appending links with variables, in the calendar and elsewhere’ is closed to new replies.