if else statement..help

Discussion in 'PHP' started by vincentweb, Apr 20, 2013.

  1. #1
    hi all, i just wanna hide the 'recent added' in subscriber profile page(author.php). as they wont be able to doing any posting in the wordpress blog..and remain original for others.(author/contributor). how can i do it with if else statement?
    for example
    <?php if ( user_role_check( 'subscriber' )): ?>
    <?php else: ?>
    <?php endif; ?>
    
    Code (markup):
    together with this
    
    <?php // Recently Added
    $link = add_query_arg('filter_type', 'user_added', get_author_posts_url($user_id));
                $args = array(
                    'view' => 'grid-small',
                    'title' => __('Recently Added', 'dp'),
                    'link' => $link,
                    'author' => $user_id,
                    'post_type' => 'post',
                    'ignore_sticky_posts' => true,
                    'posts_per_page' => 6
                );
                dp_section_box($args);
            ?>
    
    Code (markup):

     
    vincentweb, Apr 20, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    First off, welcome to why I think opening and closing PHP on every blasted line for no reason is the most {string of expletives omitted} idiotic way of writing PHP. There's a reason I call the code under the hood of turdpress some of the worst in the industry.

    Second, you want the second snippet only to run when they are NOT a subscriber, right? If so, you don't need 'else', you need the 'not' operator. (which is an exclamation point)

    <?php
    if (!user_role_check('subscriber')) {
    	$link = add_query_arg(
    		'filter_type',
    		'user_added',
    		get_author_posts_url($user_id)
    	);
    	$args = array(
    		'view' => 'grid-small',
    		'title' => __('Recently Added', 'dp'),
    		'link' => $link,
    		'author' => $user_id,
    		'post_type' => 'post',
    		'ignore_sticky_posts' => true,
    		'posts_per_page' => 6
    	);
    	dp_section_box($args);
    }
    ?>
    Code (markup):
    That should do the job, if they are not a subscriber, run the sectionBox thing... though if args isn't used again elsewhere on the page, I'd not be wasting memory putting it in a variable... same for $link
    <?php
    if (!user_role_check('subscriber')) dp_section_box(array(
    	'view' => 'grid-small',
    	'title' => __('Recently Added', 'dp'),
    	'link' => add_query_arg(
    		'filter_type',
    		'user_added',
    		get_author_posts_url($user_id)
    	),
    	'author' => $user_id,
    	'post_type' => 'post',
    	'ignore_sticky_posts' => true,
    	'posts_per_page' => 6
    ));
    ?>
    Code (markup):
    Should be functionally identical as long as you don't need those variables later.
     
    deathshadow, Apr 20, 2013 IP
  3. vincentweb

    vincentweb Member

    Messages:
    68
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    43
    #3
    unfortunate to say that i don't have basic prior knowledge of php.but i added the script accordingly and its not working. sidebar and footer was missing too.
     
    vincentweb, Apr 21, 2013 IP