WordPress.org

Ready to get started?Download WordPress

Forums

Widget Context
Can't "target by URL" (29 posts)

  1. sadhaka
    Member
    Posted 1 year ago #

    I find I can't target (e.g., "hide on selected") using the "or target by URL" scheme.

    I tried "hide on selected" from "category/books/*" but it doesn't hide from that category.

    http://wordpress.org/extend/plugins/widget-context/

  2. glamhaus
    Member
    Posted 1 year ago #

    I am having the same issue, did you find a resolution?

  3. sadhaka
    Member
    Posted 1 year ago #

    No, I haven't found a solution as yet with my WP 3.4.2 installation. I've tried every way of entering the path, but nothing works. It's a pity because if it wasn't for this bug it would be an extremely useful plugin.

    If the "target by URL" ever did work, then you would have thought that the code could be brought up to date.

  4. Michael McDonald
    Member
    Posted 1 year ago #

    I made a little progress getting 'target by URL' to work, though it doesn't make sense:

    To hide a widget on the "/relating/" page I used the string "relating".

    Theory: Initial and final slashes need to be omitted when hiding by URL

  5. sliemm
    Member
    Posted 1 year ago #

    I'm having the same issue - can't target by URL, with or without slashes. This is probably the one option I'd be using the most; if there's a fix I'd be grateful to hear it. Targeting by single page has worked temporarily for me, but I'd like to have more control.

  6. sadhaka
    Member
    Posted 1 year ago #

    @kelek - Your suggestion works! To hide a widget from my category "books" I type in the "or target by URL" box:

    category/books

    ... without leading or trailing slashes - and the widget in question now does not show in that category!

    I thought I'd tried every combination, but obviously I missed that one. Thanks!

  7. sadhaka
    Member
    Posted 1 year ago #

    I find you can also exclude further pages of the category by (e.g.):
    category/books/page/2

  8. befound
    Member
    Posted 1 year ago #

    I want to show on select urls. I'm not able to make that happen nor find specific directions. Do I want to check any of the boxes on the left?

    I want to specify a specific page (not category or post)
    This site was moved from a different server where the plugin was working. The widget is the text widget. The target url is the full path (not changed with the server move).

    Any help is appreciated.

  9. befound
    Member
    Posted 1 year ago #

    Never mind, after I saved several times it started working one by one. I did have to change from the full path to just the page and no slash.

  10. DustinRyan
    Member
    Posted 1 year ago #

    Doesn't work no matter what combo I try. This would be really helpful if it worked. Do I need to set any category settings in addition to configuring the widget URL and such?

  11. grahamtwo
    Member
    Posted 1 year ago #

    I put a little debug line into widget-context.php to echo $url; just before the return from function get_current_url()

    On my local site it showed https://localhost/mypage

    Not at all what I was expecting, but using that string gets a match on target by URL.

    Better still...seems you can use the * wildcard anywhere on the URL.

    e.g. */mypage/*

    Hope that helps.

  12. visualeyes80
    Member
    Posted 1 year ago #

    Make sure you don't have an empty carriage return in "or target by URL" field.

  13. tarheit
    Member
    Posted 1 year ago #

    I found *category/mycategory* works

    but any other varient doesnt' seem to work ie. /category/mycategory* or /category/mycategory/*

    It seems like it works, but is a bit too picky (and the examples given in the plugin itself don't work)

  14. treccase
    Member
    Posted 1 year ago #

    It worked for me when i entered the page like this:

    no checkbox clicked

    url: xxx.com/some-name-of-page/

    i used: */some-name-of-page

    notice there is no end slash

  15. adewhite
    Member
    Posted 1 year ago #

    I've found the solution that worked for me. To use this you have to first set the wordpress permalinks under 'Settings - Permalinks'. Use Custom Structure e.g. /%category%/%postname%/ which means your permalinks or URL (using an example of a category called 'events') will look like this:

    Category index pages: http://abc.com/category/events/
    Post pages: http://abc.com/events/public-stoning-on-monday/

    Settings for this widget can thus be:

    category/events (for the events index page)
    events/* (for all pages under the category events)

    Hope that helps.

  16. promotioncreatives
    Member
    Posted 1 year ago #

    Just Type in the page without any other markup like this ==>> mobile-website-design No / or any symbols.

  17. sjmills93
    Member
    Posted 1 year ago #

    Hoping someone in this support stream can help. First off my PHP knowledge is minimal, so please keep that in mind when posting a possible solution.

    I posted my problem as a new thread - but have not received any suggestions in 4 days. I note the plugin author is very silent on responding to any posts for help - and yet solicits financial support!

    Anyhoo....

    My homepage is using a custom template that is based on the default SIDEBAR-PAGE.PHP template (WordPress 3.5). I included some query code within the content div of this template to enable me to post ONLY those posts to that page that I wanted. The query code was developed by someone else and I've used it without issue on other websites.

    However, I am unable to get Widget Context to display specific widgets on that custom template (which is my homepage!) other than a universal site widget called "Support"

    So somehow this plugin IS getting ONE widget to display but not the specific ones I want.

    I've tried all of the various suggestions above for targeting the page by URL, category, tag etc - NONE work.

    The page ID is "4". I'm sure that if I could add a line to the "Check by tag settings section" (around line 324) telling the plugin to post to page 4 I could resolve the issue - but I don't know enough PHP to do this and all my attempts at writing the code have either been completely ineffective or rendered a coding error so the page doesn'nt display at all.

    The homepage URL is actually http://www.stjosephmuseum.ca/page/4 and if you type that URL into browser's address line the widgets DO show up - just NOT when you click on the "HOME" button.

    Any thoughts on how to resolve this? I would greately appreciate your help.

    Here's the custom template code for my homepage as reference (modified SIDEBAR-PAGE.PHP template) - you'll note it resets the post query - but...

    <?php
    /**
     * Template Name: Homepage Sidebar Template
     * Description: A Page Template that adds a sidebar to pages
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); ?>
    
    		<div id="primary" style="margin: 0 -26.4% 0 0%; width: 74%; padding:0;float:left;display:inline;">
    
    			<div id="content" style="margin: 0%;" role="main">
    
    				<?php the_post(); ?>
    
    					<?php get_template_part( 'content', 'page' ); ?>
    
                        <?php
    					/* Lets see if we have a category to display */
    					global $post;
    
    					// Save our page posts to use later
    					$tmp_post = $post;
    					$catid = "";
    
    					// Do we have a category set on the custom fields
    					$meta_cat = get_post_meta($post->ID, 'category', true);
    
    					// Do we have an order set on the custom fields
    					$asc = get_post_meta($post->ID, 'asc', true);
    
    					// Do we want to display thumbnail and excerpts list?
    					$excerpt = get_post_meta($post->ID, 'list', true);
    
    					// Do not rely on what the admin entered
    					$order = $asc ? 'ASC' : 'DESC';
    					if( $meta_cat ) {
    						// If we have a meta value is it numeric or a slug, return an id
    						$catid = is_numeric( $meta_cat ) ? $meta_cat : get_cat_ID($meta_cat);
    					}
    
    					// No category ID so use the page slug to find a category
    					if( !$catid ) $catid = get_cat_ID($post->post_name);   
    
    					// If we have a category id we can get the category posts
    					if( $catid  && is_numeric( $catid ) ) {
    						$do_not_show_stickies = 1; // 0 to show stickies
    						$args = array(
    							'cat' => $catid,
    							'paged' => $paged,
    							'order' => $order,
    							'ignore_sticky_posts' => $do_not_show_stickies
    						);
    
    						$wp_query = null;
    						$wp_query = new WP_Query();
    						$wp_query->query( $args );
    
    						// Output our Query
    						if ( $wp_query->have_posts() ) :
    
    							twentyeleven_content_nav( 'nav-above' ); 
    
    							while ( $wp_query->have_posts() ) : 
    
    								$wp_query->the_post();
    								if( $excerpt ) :
    									get_template_part( 'content', 'excerpt' );
    								else :
    									get_template_part( 'content', get_post_format() );
    								endif;
    							endwhile;
    
    							twentyeleven_content_nav( 'nav-below');
    						endif;
    					}
    				?>
    
    				<?php
    					// Reset the post to the page post
    					$post = $tmp_post; 
    
    				?>
    
    					<?php comments_template( '', true ); ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
  18. memelab
    Member
    Posted 1 year ago #

    as @visualeyes80 said, make sure that you don't have a blank line after your URLs in the show URL box!

  19. sjmills93
    Member
    Posted 1 year ago #

    Thank for your help memelab - but there was no extra line after the URLs list, HOWEVER I did find a solution!!!!

    Google searched and discovered another Support Forum for a similar widget at http://themeshaper.com/forums/topic/widget-logic-problem-with-is_home-and-blog-versus-static-page where another user was trying to display context sensitive widgets on a static homepage (and additionally in my case a custom version of sidebar-page.php.)

    "lance1572" tried adding '<?php wp_reset_query(); ?>' to the end of his query function and solved his problem

    I added the same code to the bottom of my query function and it worked!

    Just in case this helps someone else, here's the revised code for my customed sidebar-page.php template:

    <?php
    /**
     * Template Name: Homepage Sidebar Template
     * Description: A Page Template that adds a sidebar to pages
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); 
    
    ?>
    
    		<div id="primary" style="margin: 0 -26.4% 0 0%; width: 74%; padding:0;float:left;display:inline;">
    
    			<div id="content" style="margin: 0%;" role="main">
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    					<?php get_template_part( 'content', 'page' ); ?>
    
                        <?php
    					/* Lets see if we have a category to display */
    					global $post;
    
    					// Save our page posts to use later
    					$tmp_post = $post;
    					$catid = "";
    
    					// Do we have a category set on the custom fields
    					$meta_cat = get_post_meta($post->ID, 'category', true);
    
    					// Do we have an order set on the custom fields
    					$asc = get_post_meta($post->ID, 'asc', true);
    
    					// Do we want to display thumbnail and excerpts list?
    					$excerpt = get_post_meta($post->ID, 'list', true);
    
    					// Do not rely on what the admin entered
    					$order = $asc ? 'ASC' : 'DESC';
    					if( $meta_cat ) {
    						// If we have a meta value is it numeric or a slug, return an id
    						$catid = is_numeric( $meta_cat ) ? $meta_cat : get_cat_ID($meta_cat);
    					}
    
    					// No category ID so use the page slug to find a category
    					if( !$catid ) $catid = get_cat_ID($post->post_name);   
    
    					// If we have a category id we can get the category posts
    					if( $catid  && is_numeric( $catid ) ) {
    						$do_not_show_stickies = 1; // 0 to show stickies
    						$args = array(
    							'cat' => $catid,
    							'paged' => $paged,
    							'order' => $order,
    							'ignore_sticky_posts' => $do_not_show_stickies
    						);
    
    						$wp_query = null;
    						$wp_query = new WP_Query();
    						$wp_query->query( $args );
    
    						// Output our Query
    						if ( $wp_query->have_posts() ) :
    
    							twentyeleven_content_nav( 'nav-above' ); 
    
    							while ( $wp_query->have_posts() ) : 
    
    								$wp_query->the_post();
    								if( $excerpt ) :
    									get_template_part( 'content', 'excerpt' );
    								else :
    									get_template_part( 'content', get_post_format() );
    								endif;
    							endwhile;
    
    							twentyeleven_content_nav( 'nav-below');
    						endif;
    					}
    				?>
    
    				<?php
    					// Reset the post to the page post
    					$post = $tmp_post; 
    
    				?>
    
    					<?php comments_template( '', true ); ?>
    					<?php endwhile; // end of the loop. ?>
    					<?php wp_reset_query(); ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
  20. annalan
    Member
    Posted 1 year ago #

    weird thing, I been trying to make it work and searched for different solutions.
    Finally fixed it work but changing some code in widget-context.php -
    Found on http://wordpress.org/support/topic/plugin-widget-context, post by jpmorganjr:

    In widget-context.php change this function:
    
    function get_current_url() {
    if ($_SERVER['REQUEST_URI'] == '')
    $uri = $_SERVER['REDIRECT_URL'];
    else
    $uri = $_SERVER['REQUEST_URI'];
    
    $url = (!empty($_SERVER['HTTPS']))
    ? "http://".$_SERVER['SERVER_NAME'].$uri
    : "http://".$_SERVER['SERVER_NAME'].$uri;
    
    if (substr($url, -1) == '/')
    $url = substr($url, 0, -1);
    
    return $url;
    }
    
    To this one:
    
    function get_current_url() {
    $uri = $_SERVER['REQUEST_URI'];
    if (substr($uri, -1) == '/') $uri = substr($uri, 0, -1);
    return $uri;
    }
    
    You won't be able to use the http or https versions of the target by URL anymore, but you shouldn't be able to anyway because all the widgets are on the same domain.
    
    If I had more time I'd do a proper debug, but I'm in a hurry and wanted to share this because it's the only plugin that offers this solution and I know plenty of others need it to work!!

    Then had to type */pagename (with the star before trailing slash) and it works :)

  21. annalan
    Member
    Posted 1 year ago #

    btw, big thanks to @jpmorganjr :)

  22. missmandarin
    Member
    Posted 1 year ago #

    So what is really working if I need to insert the URL of pages I want to hide/show a widget on?
    It is a bit confusing, and disappointing. I have updated the plugin thinking it would have worked, but it actually does not.
    it 's one of the best plugins ever and probably the most useful one, but now it is actually absolutely useless, because I can not set up the widgets to show on different pages.

    i tried url with / or without, no space after the url, nothing worked.
    Any FINAL clear help ? or an update of the plugin maybe?

  23. dee987
    Member
    Posted 1 year ago #

    Hi,

    I am trying to show widgets on specific URLs/tags. It works then stops working.

    Is this an issue with WP 3.5.1? Is their a fix?

    Thanks for the help.

  24. raiodeluz18
    Member
    Posted 1 year ago #

    Hi to all

    I have a problem that I have been trying to solve for a while regarding the Widgets option and Custom Menu.

    My question is: why doesn't my Custom Menu in Widgets work, when I ask to target by URL and only show on these selected links? I have Widget Context plugin installed so that this option is available.

    I put in my Title, I select the menu and then in the Widget Context I select, show on selected. In the "or target by URL" tab, I include all the links, one in each line, that I want my Custom Menu to appear on...but it's not working.

    Is anyone familiar with this process and has any idea as to how this can be solved?

    Thanks for all your help.

    Marly

  25. popgirl23
    Member
    Posted 1 year ago #

    Hey after struggling through all of this I found something that worked for me. Give it a try.

    I have two "pages" of posts representing or showing two different categories.

    I need different sidebars for each category, that needed to stay consistent on every "page" or post within the category.

    In order to get the correct sidebar widgets for each category and their child pages and the single post, I had to do this:

    FIRST make sure your permalinks have this structure:

    Custom Structure: /%category%/%postname%/

    Then go to your widget and do the following:

    Widget Context: "Show On Selected"

    and

    or target by URL:
    category/blog/
    category/blog/*
    /blog/*

    Of course switching my terms to your terms. Thats it.

    If I tried to just one line of url it didn't stay in place as I navigated within the category tree.

    I found this frustrating and time consuming before figuring it out. Hope it helps.

  26. saitam1953
    Member
    Posted 1 year ago #

    Finally i could resolve this problem as you can see in the picture:

    http://josematias.pt/eletr/

    e neste o plugin que eu pretendia, com a palavra 'TESTE!!!!'.

    http://josematias.pt/eletr/eletricidade-eletronica/livros/

  27. cableghost
    Member
    Posted 1 year ago #

    I rolled back to 0.7.2 and URL targeting worked again.

    Is there a resolution for the latest version that works in all situations?

  28. Rootside
    Member
    Posted 1 year ago #

    Had the same problem on one particular website. This worked for me:

    */pagename

    On other servers, just using the pagename without any slashes or placeholders usually works just fine – I suspect it has to do with the way your webhost sets things up: this problem occured on a cheap hosting package.

  29. Dzynit
    Member
    Posted 12 months ago #

    Using the */pagename worked for me also.

    @Rootside, I'm wondering if it could be the wordpress seo plugin causing this since it does it's own rewriting on top of the permalink settings. I was having trouble hiding on a post which if going only by permalinks settings would be category/announcements/pagename - but with wordpress seo active, viewing the page rewrites to just pagename.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.