Wordpress Discussion

  • Started
  • Last post
  • 163 Responses
  • pockets

    All Wordpress related Topics & Questions goes here.

    Cheers.


  • fadein113

    Cool - I will be frequenting :)

  • oey2

    Me too!

    :)

  • fadein110

    In fact I will kick it off - I need a little advice on a loop:

    I have everything working in this loop except excluding the post that you are viewing the loop on - so this is kind of a related posts loop from a custom post type. Got it all working apart from excluding the current post - random works fine etc.

    Any ideas what I have missed?

    query_posts($the_query);

    // Reset and setup variables
    $output = '';
    $temp_title = '';
    $temp_link = '';
    $temp_url = '';

    // the loop

    $exclude = $GLOBALS['current_id'];

    $args = array(

    'post__not_in' => array($exclude), 'post_type'=>'our-work', 'orderby'=>'rand', 'posts_per_page'=>'3'

    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();

    $temp_title = get_the_title($post->ID);
    $temp_link = get_permalink($post->ID);
    $img_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

    // output all findings - CUSTOMIZE TO YOUR LIKING
    $output .= "<li class='workitem workitem2' style='background:url($img_url); background-repeat: no-repeat!important;
    background-size: cover!important;
    background-position: center center!important;'><a href='$temp_link'><span>$temp_title</span></a></li>

    • what are you trying to do?pockets
    • All I got is how to exclude the current post from the loop?pockets
    • its a related posts feed on a post page - but basically I want to pull in 3 random posts excluding the 1 you are currently viewing.fadein11
    • is it working but displaying current post on related posts loop?pockets
    • there's one way you can do it off the top of my head, but the post limit would vary, you just need to call the function that can pull the current id of...pockets
    • ..of the random related posts and exclude the current post from it. I'll write you an example, and you replace the missing variablespockets
    • thanks mate!fadein11
  • ArmandoEstrada0

    Not sure why you have this:

    $exclude = $GLOBALS['current_id'];

    I would:

    $this_post = $post->ID;

    then:

    'post__not_in' => array($this_post)

    maybe?

    • the latter didn't work. I tried it in various ways. Apparently it has issues with custom post types when pulling random posts.fadein11
    • tried all the conventional stuff you would do with a normal post type.fadein11
  • pockets0

    fadein:

    $current_postID = '438'; //Replace 438 with function that pulls current id
    if($randID == $current_postID ){}
    else{
    $temp_title = get_the_title($post->ID);
    $temp_link = get_permalink($post->ID);
    $img_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    }

  • pockets0

    something like this:

    $current_postID = $post->ID;
    if($randID == $current_postID ){}
    else{
    $temp_title = get_the_title($post->ID);
    $temp_link = get_permalink($post->ID);
    $img_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    }

    • $randID would be the ID of the related post from the looppockets
    • I just used a dummy variable for you to replace with the actual functionpockets
    • if you send me the actual script so I can test it I can make it workpockets
    • Thank you! have posted below.fadein11
  • mg333

    Useful to all:

    • i have this shit printed as a posterpockets
    • I hope it takes up an entire wall in your home. LOL.mg33
    • I'm not sure how this works but I'm distracted right now. Gonna return to it later.oey
    • updated version: https://wphierarchy.…FixMiller
  • mg334

    A few tips from my own experiences over the past several years building, customizing, and running WP sites:

    1. Always, always, ALWAYS use some form of security plugin to manage your site's security, files, access, and monitor it regularly. Know whatever tool you use almost as well as you know WP itself. iThemes and Wordfence are both highly rated, and come with subscription services that have advanced features.

    2. Periodically run an anti-virus specific plugin beyond whatever you use for security. Learn the ins-and-outs of what files regularly change based on how the plugin operates.

    3. Gain a fairly good understanding of basic PHP. That has helped me tremendously when seeking out files that had malicious code added to them after a hack. Learn what base64 code is and learn how to identify it, and patterns used with it in malicious code. Could go on and on about this, but look into it.

    4. Always use a child theme for your customizations.

    5. Backup regularly, either manually or with a scheduled service. Follow the suggestions on where to and where not to keep your backups (ex: not on the same root folder as the site itself).

    6. Make sure that via your security plugin, you don't have an account called "admin."

    7. If you're customizing CSS, use an actual file that you edit on the server or in the WP Editor, and not a custom CSS field that's managed within the theme. I don't know... there's something that causes a lot of frustration with the theme-based custom CSS fields; it's hard to find where that CSS is actually managed in a file, and what the rules are about what it overwrites. It's just so much easier to know you have a file that stands alone to manage, and uses !important for some things that are really hard to overwrite.

    8. Don't code, customize, tweak the site, etc. when you're tired. I learned my lesson editing a site once when I couldn't keep my eyes open. Totally lost track of the edits I was making, didn't track them in notepad, and was totally confused the next day.

    9. Don't worship Satan.

    • #9 blasphemy!moldero
    • https://www.youtube.…moldero
    • Very sound advice, but this is also a part time job in itself. Educate the client on the risks and charge them a maintenance fee.ArmandoEstrada
    • I just did 8. But i was experienced enough to know i had to take notes. Solid advice here fellas and fellaettesrabbit
  • fadein110

    @pockets - here is the full function. Thanks again!

    function custom_alsolikequery_shortcode... {

    // Defaults
    extract(shortcode_atts(array(
    "the_query" => ''
    ), $atts));

    // de-funkify query
    $the_query = preg_replace('~&#x0*([0-9a-f... 'chr(hexdec("\\1"))', $the_query);
    $the_query = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $the_query);

    // query is made

    remove_all_filters('posts_orderb...
    query_posts($the_query);

    // Reset and setup variables
    $output = '';
    $temp_title = '';
    $temp_link = '';
    $temp_url = '';

    // the loop

    $exclude = $GLOBALS['current_id'];

    $args = array(

    'post__not_in' => array($exclude), 'post_type'=>'our-work', 'orderby'=>'rand', 'posts_per_page'=>'3'

    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();

    $temp_title = get_the_title($post->ID);
    $temp_link = get_permalink($post->ID);
    $img_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

    // output all findings - CUSTOMIZE TO YOUR LIKING
    $output .= "<li class='workitem workitem2' style='background:url($img_url); background-repeat: no-repeat!important;
    background-size: cover!important;
    background-position: center center!important;'><a href='$temp_link'><span>$temp_title</span></a></li>

    ";

    endwhile; else:

    $output .= "nothing found.";

    endif;

    wp_reset_query();
    return $output;

    }
    add_shortcode("loopalsolike", "custom_alsolikequery_shortcode...

    • has to be a shortcode as it needs to be inserted into the content here and there.fadein11
    • truncated? wheres the whole thingpockets
    • "..." ?pockets
    • code looks all sorts of fuckedpockets
    • paging fadeinpockets
    • i give uppockets
    • Sorry UK time... That code works fine except excluding the current postfadein11
    • ah yes it is truncated - thought it would be okay as short.fadein11
    • It was 11am and I had to go to bed - thought I had commented that but hadn't - apologies.fadein11
    • 11pm - God I need coffee.fadein11
  • ArmandoEstrada2

    Im guessing we can't embed pastebin etc here, so maybe we should link to pastebin/etc here instead of pasting a bunch of code....

  • fadein111

    Sorry Pockets - thought it would be okay as short. Here you go:

    http://pastebin.com/hwyNVALd

  • sted1

    I use these functions on corporate sites:

    http://pastebin.com/cwGinwAw

  • mekk-2

    If an online agency suggests WP for your project they're absolute amateurs in almost every case and resell you a $20 template for $10k, only setting it up and doing minor CSS changes.

    • generaliser is generalising.fadein11
    • As a Wordpress designer/developer myself my experience is the opposite - by far most of my projects are custom Wordpress builds.fadein11
    • what fade said. I deny every project where the client asks to use a $20 template,sted
    • I occasionally use a template if a client has no or little budget and I know it will be superquick but even those generally come out looking v.different.fadein11
    • 100% custom work across the board. We use Zurb as a starting point, so basically a blank canvas.ArmandoEstrada
    • not true at all. we build themes from scratch. it's a great free CMSdbloc
  • hans_glib0

    i'm hacking a child theme together at the mo, using a custom css file to override the main theme as and when.

    but why won't my custom css override plugin css files? for instance, i'm using responsive tabs plugin, and have to hack the min.css file in the plugin folder to get any changes to work. this can't be good, can it?

    • the plugins are adding their styles via wp_enqueue_style, you simply need to dequeue them. but this depends actually how your original theme was builtsted
    • but actually if you just simply copy the rules from the tabs plugin css to the custom and add your own stuff it should work.sted
    • ^ yep what he said - and occasionally you may have to use !important in your styles to override stuff - not that this is a nice way of working.fadein11
    • interesting, thankshans_glib
  • microkorg0

    Anyone use BUDDYPRESS before?

    Lets your site users create profiles.
    Could it for example allow the users to post up their own submissions to the site. Not via the wordpress admin though, can you control what they post with specific fields they had to fill in.

    e.g

    title, description, link to video

    and then this would appear as content on the site in a template style (so they cant fuck up the site).

    ?

    • I'm working on site at the moment using bp with user submitted content using front end forms - USP Pro plugin.Xopher
    • Normal Wordpress can do all you need to do. Buddypress creates a social network not unlike Facebook. If you want jus that functionality I would stick to core WPfadein11
    • Custom post type plus Advanced custom fields.fadein11
    • Look into custom post types - there's a good plugin for them if you don't want to code them then create custom fields using ACF plugin then create a templatefadein11
    • for displaying that custom post.fadein11
    • Thanks for those little snippets of info. Was just wanting to know if possible. Good to know it is. Project is in talks at the moment. I wont be building.microkorg
    • Think do want BuddyPress though so that users can create profile pages and such.microkorg
    • Ah okay - but this is all possible within core Wordpress - all users have a profile on the author page - you just need to add more fields as required.fadein11
    • author.php. but yes if you want facebook style profile then BP is prob what you need. A huge amount of styling involved with BP so cost that in.fadein11
    • Gravity Forms can submit to a draft post (or custom post type), with custom fields.Nathan_Adams
    • The theme ive bought has BP styling already certainly for some pages :)microkorg
  • fadein110

    Pockets Bump

    • i am so hung over atm. ill look at it laterpockets
    • haha - no probs mate - no panicfadein11
  • fadein111

    Recovered pockets bump :)

  • Milan0

    Has anyone ever tried transferring content from a WordPress database to another CMS?

    I've never had to do it, but it looks like it would be an absolute nightmare because of the DB structure.

    • I think the key would be outputting the data into a format (XML or whatever is needed) that could be imported into the other CMS.yuekit
    • ^ yep what he says - you can export all content as XML easily. And there are various other tools for porting data.fadein11
  • fadein110

    Pockets - still struggling with this loop - cannot find a fix - any ideas please? I can pay if it will take some time.

    • whats da prob doc?rabbit
    • nvm ill read it below. havent slept in 24hrs. lol.rabbit
    • ok i cant read that shit right now i dont even know which was is left. ill look laterrabbit
  • ideaist1

    Looking for WordPress security-related plugin / information; 3 sites malwared in the last few days.

    : (

    Thanks in advance!

    • Wordfence. But I recommend migrate the essential content to a new install/databaseSalarrue
    • Sucuri is good for scan and clean too.Salarrue
    • iThemes Security is another popular option.noneck
    • What they said.ArmandoEstrada
    • Wordfence+fail2ban goes quite nicely.
      Sucuri is sucky, iThemes WTF?
      sted
    • i like sucuri :(pockets
    • +1 for scurri - they fixed "wp pharma hack" on one of my sites in like 5 min.dconstrukt