• hello,

    i have a site that requires the same widgets to be displayed on most posts but with different content, for example a music player that is in the same place on all posts but the content of it changes depending on the post you are on.

    i implemented a solution similar to this on joomla that enabled different header images to be displayed according to their Itemid (eg their ‘page number’). someone had suggested that i move the background to an inline style which used the code:

    <div id="template_top" style="background:url('../images/header<?php echo JRequest:: getVar ('Itemid')?>.jpg') no-repeat">

    then i had a folder full of header images that corresponded to the Itemid, ie 63.jpg, 54,jpg etc and if someone went to a page that had an Itemid of 63, then the 63.jpg header image was used.

    so i am just wondering if something like this is possible in wordpress?

    i have tried the widget logic plugin and that is awesome, but if i only used this as a solution i would end up having lots of widgets with conditional tags, as each post would need it’s own widget with a trigger of is_single(’17’) etc.

    but what i need is one widget that contains code which generates different output depending on the post you are viewing.

    i have a few different variables, but the first i am looking at is in the instance of a music player widget:

    [jwplayer config="Widget Player" mediaid="219"]

    here, the ‘mediaid’ would need to correspond to the post that was being viewed.

    any ideas appreciated – thanks!

    EDIT:

    Looking into ‘Variable Sidebar Content‘ conditionals now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rw1

    (@rw1)

    Could custom fields be added to a post and then pulled into a widget using variable sidebar contents?

    Thread Starter rw1

    (@rw1)

    Ok i’ve created a custom field in a post:

    name: new_key
    value: test

    now i am trying to output this value ie ‘test’ in a widget.

    i think the code in the widget should be something like:

    get_post_meta($post_id, $key, $single);

    but i don’t know exactly how to reference it.

    am trying things like:

    <?php $meta_values = get_post_meta($post_id = get_the_ID(); $key = new_key, $single = true); ?>

    which would hopefully:

    – get the current posts id
    – read the value of it’s ‘new_key’ field
    – display the value

    but getting a blank widget at this stage…

    am referring to the following codex articles:

    custom fields
    get_the_ID()
    get_post_meta()

    Thread Starter rw1

    (@rw1)

    I came across the ‘Get Custom Field Values‘ plugin and this seems to automate the process of what i am trying to achieve above.

    Only problem at the moment is that it is displaying the shortcode text on the front end rather than displaying the media player.

    Will post back when i find a solution!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘creating widgets that display different content based on conditionals.’ is closed to new replies.