I have plugin by WPMU that creates a membership system for your wordpress theme. Im trying to make it display a gallery only when a user is a premium member and Im completely lost. My code basicly grabs part of the url and pastes it into variables in my susbscription div to draw the information needed. I need it to check if the user is logged in but Im not sure how to do that. Here is my code, Thanks:
<?php get_header(); ?>
<?php
$url = $_SERVER['REQUEST_URI'];
$url = rtrim($url, '/');
function drawId($url) {
return array_pop(explode('-', $url));
}
?>
<div class="main-container col2-right-layout">
<div class="main">
<p><?php echo drawId($url); ?></p>
<?php get_template_part('loop');?>
<div id="subscription">
<p><?php echo nggcf_get_gallery_field(drawId($url), "Gallery Text"); /* where 1 is the gallery id */ ?></p>
<?php echo do_shortcode('[nggallery id='.drawId($url).']');?>
</div>
</div><!-- .main -->
</div><!-- .main-container col2-right-layout -->
<?php get_footer(); ?>
The following is copied and pasted from the plugin's support forms:
you can try any of the following for your customization needs:
current_user_is_member()
current_user_on_level($level_id)
current_user_on_subscription($sub_id)
And of course, you can get the level_id and sub_id from the respective membership level and subscription lists.
if you want to check if a user is logged in, in wordpress, it is just a condition like this:
if(is_user_logged_in()){
//do you stuff
}
hope this help. read more here
This plugin allows only people that are logged in to your site to use the site:
http://wordpress.org/extend/plugins/private-wp/
Maybe by creating memberships though your admin panel you could target the the user in that way.
Related
I would like that my php detects seperatly images (media) and text, from a same wordpress post, in regard to display them in different columns. I am using Bootstrap, and I would like different display of each (text and image) according to the screen size.
Here is a code I have that displays all of the content of my post (image and text) at once, it works perfectly :
<div class="container">
<?php if (have_posts()): ?>
<div class="container">
<?php while(have_posts()): the_post(); ?>
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-12">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
I would like the same way of loading content but instead of having just
<?php the_content(); ?>
I would like something like this to place text and image (of same post) in different div class:
<?php the_image(); ?>
AND
<?php the_text(); ?>
I know this is wrong code but I am trying to be clear in my explanation. I need that my client does not touch any of code, also shortcode in Wordpress post. Any input or advice would be very appreciated!
Many thanks!
Thank you for your answer! Lars Beck, you solved my problem!
Here is the code I was looking for:
<?php
//get content from back office , filter imgs except featured img to place them later in <div id='img_content_right'>
$content2 = get_the_content();
$removed_imgs = array();
$content2 = preg_replace_callback('#(?!<img.+?id="featured_img".*?\/>)(<img.+? />)#',function($r) {
global $removed_imgs;
$removed_imgs[] = $r[1];
return '';
},$content2);
//add filter to the_content to strip images except img_menu et featured_img
add_filter('the_content', 'strip_images',2);
function strip_images($content){
$content=preg_replace('/(?!<img.+?id="img_menu".*?\/>)(?!<img.+?id="featured_img".*?\/>)<img.+?\/>/','',$content);
return $content;
}
the_content();
?>
<div id='img_content_right'>
<?php
//append the images stripped from content
foreach($removed_imgs as $img){
echo $img;
}
?>
</div>
There is no way, to separate out images from the content section if they have just been included as part of the content.
Wordpress has featured image functionality built in for you. so you can use the_post_thumbnail() to echo out the image. Maybe this question can help you Wordpress featured image code
If this isn't enough for you and you need more flexibility you might want to look at advanced custom fields plugin - https://www.advancedcustomfields.com/ it makes it easy for you to add your own fields of any type you want.
I received this request from my client:
"We are still experiencing LOTS of problems with state aid recipients trying to log into their state aid account through the “My Account” function, even though you added language to direct them elsewhere. To solve this problem, would it be possible to remove the “Student Disability”, “Contact Us”, and “My account” links from the top of the State Aid pages? "
In researching and found that those links are generated in the searchform.php file of my theme.
How do I exclude that page from applying the get_search_form() function in the head.php? This is what the navigation looks like with that function:
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
This is the site: http://Riseupms.com/state-aid/
Is it possible?
Assuming that the Page name of that particular page is "STATE FINANCIAL AID" you can do it like this
<?php if(!is_page( 'STATE FINANCIAL AID' ) { ?>
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
<?php } ?>
or you can exclude it by page id like this
<?php if(!is_page( 2341 ) { ?>
<div id="top-navigation">
<?php get_search_form(); ?>
</div>
<?php } ?>
or u can simply do it with css
body.page.page-id-2341 #nav-bar li#item1,
body.page.page-id-2341 #nav-bar li#item2,
body.page.page-id-2341 #nav-bar li#item3 {
display:none;
}
Hello and thanks for reading. I am a .NET developer and don't know PHP (Although I am working on learning on the job) and what I am working on was made my consultants that we dont have contact with anymore. When a news post is clicked it appears to display using a template single.php. Followed is the code for this page:
<div id="marketBanner">
<div id="banner">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/services-banner.jpg" alt="" />
</div>
<div id="breadcrumbWrap">
<div id="breadcrumbs">
<?php
if(function_exists('bcn_display'))
{
bcn_display();
}
?>
</div>
</div>
</div>
<div id="content">
<div class="left">
<h2><?php the_title(); ?></h2><br />
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="the_details">
Posted: <?php the_date(); ?> | View All News
</div>
<?php the_content(''); ?>
<?php endwhile; endif; ?>
</div>
Why does this page get used when a post is chosen? I want only a certain category of post to use this page and another category of post to use a different template. How do I achieve this?
You need to study the Wordpress Template Hierarchy # https://codex.wordpress.org/Template_Hierarchy#Single_Post_display
A template (PHP file) is looked for in this order (only on wordpress).
1 - single-{post_type}.php - If the post type were product, WordPress would look for single-
2 - product.php
3 - single.php
4 - index.php
In your case I would use single.php to create a template for the average post then specifically create a template for the one you want different using single-'post_type'.php
You can change the post type when creating a post.
Take a look at the Wordpress Template Hierarchy. It explains which templates get used and will probably be super helpful if you're just starting out with WP. You can use WP syntax to create category pages - but at the archive level - not the single post level.
To create separate pages based on post categories see here and below:
<?php
$post = $wp_query->post;
if (in_category(9)) {
include (TEMPLATEPATH.'/single-specific9.php');
return;
}
if (in_category(8)) {
include (TEMPLATEPATH.'/single-specific8.php');
return;
}
if (in_category(11)) {
include (TEMPLATEPATH.'/single-specific11.php');
return;
}
I'm new to Social Engine and Zend frame work. I want to customize Header and footer of my application. My default.tpl contains bellow code.
</head>
<body id="global_page_<?php echo $request->getModuleName() . '-' . $request->getControllerName() . '-' . $request->getActionName() ?>">
<div id="global_header">
<?php echo $this->content('header') ?>
</div>
<div id='global_wrapper'>
<div id='global_content'>
<?php //echo $this->content('global-user', 'before') ?>
<?php echo $this->layout()->content ?>
<?php //echo $this->content('global-user', 'after') ?>
</div>
</div>
<div id="global_footer">
<?php echo $this->content('footer') ?>
</div>
</body>
</html>
Now I want load some widgets in footer section. Can any one suggest me how to customize <?php echo $this->content('footer') ?>. And where the footer file located in my application?.
Thanks in advance.
First add a script location to your view and then inside your layout file just use render() or partial() depending on your needs.
ie:
In your controller:
$this->view->addScriptPath('/partials'); // Put your custom files here
In your view:
$this->render('customview.phtml')
See here for more info. Try to use render() instead of partial() as it's quicker
content('footer') ?> in your code calls view Helper Content.php
Content Page calls LoadContent method which collects data from two tables in Social engine
engine4_core_pages table which has a value of 2 as page_id for footer. Based on this page_id (2), engine4_core_content table will be queried, which has the list of widgets that are loaded. For now, one widget is used to display footer in content table is
"core.menu-footer" widget. This widget is loaded in footer area of the template (default.tpl).
I have an admin link with a div id "admin". Sessions are started when a user is logged in to show if it is a normal user or an admin. Normal users can't access the files for admin, but can still see the admin link.
Is there a way to make it so normal users can't see the link, using only php or html, without jquery or jscript or any of those.
Using interleaved PHP & HTML with standard PHP syntax:
<?php
if ($user_is_an_admin) {
?>
<div id='admin'>
Only admins can see this...
</div>
<?php
}
?>
Alternate templating syntax:
<?php if ($user_is_an_admin): ?>
<div id='admin'>
Only admins can see this...
</div>
<?php endif; ?>
Not interleaving, PHP only:
if ($user_is_an_admin) {
echo "<div id='admin'>
Only admins can see this...
</div>
";
}
You'll need to use conditionals inside of your views:
<?php if($_SESSION['adminid'] == 1234): ?>
<!-- Admin div goes here -->
<?php else: ?>
<!-- Admin link goes here -->
<?php endif; ?>